获取传单地图上用mapbox搜索到的地址的lat/long
Getting the lat/long of the address searched with mapbox on the leaflet map
我有这样一个场景。用户正在输入目的地地址。他选择输入下方的地址之一。而我要记录这个地址的经纬度。我正在使用地图框 api。我怎样才能做到这一点?我在文档中找不到或看不到它。
HTML:
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<label class="control-label geocoder" for="geocoder">Address</label>
<div id="geocoder" class="geocoder"></div>
</div>
</div>
</div>
JS:
<script type="text/javascript">
accessToken = 'xxxxxxxx';
var mapboxTiles = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=' + accessToken, {
attribution: '© <a href="https://www.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
tileSize: 512,
zoomOffset: -1
});
var map = L.map('map')
.addLayer(mapboxTiles)
.setView([39.525247, 34.160501], 6);
var geocoder = new MapboxGeocoder({
accessToken: accessToken,
mapboxgl: mapboxgl
});
document.getElementById('geocoder').appendChild(geocoder.onAdd(map));
</script>
点击搜索输入下方的地址会在地图上显示该位置。当我点击那个地址时,我想提醒地址的经纬度。我该怎么做?谢谢
我解决了我的问题。我写下任何人需要帮助的答案。
accessToken = 'xxxxxxxx';
var mapboxTiles = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=' + accessToken, {
attribution: '© <a href="https://www.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
tileSize: 512,
zoomOffset: -1
});
var map = L.map('map')
.addLayer(mapboxTiles)
.setView([39.525247, 34.160501], 6);
var geocoder = new MapboxGeocoder({
accessToken: accessToken,
mapboxgl: mapboxgl
});
document.getElementById('geocoder').appendChild(geocoder.onAdd());
geocoder.on('result', e => {
console.log(e.result)
})
我有这样一个场景。用户正在输入目的地地址。他选择输入下方的地址之一。而我要记录这个地址的经纬度。我正在使用地图框 api。我怎样才能做到这一点?我在文档中找不到或看不到它。
HTML:
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<label class="control-label geocoder" for="geocoder">Address</label>
<div id="geocoder" class="geocoder"></div>
</div>
</div>
</div>
JS:
<script type="text/javascript">
accessToken = 'xxxxxxxx';
var mapboxTiles = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=' + accessToken, {
attribution: '© <a href="https://www.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
tileSize: 512,
zoomOffset: -1
});
var map = L.map('map')
.addLayer(mapboxTiles)
.setView([39.525247, 34.160501], 6);
var geocoder = new MapboxGeocoder({
accessToken: accessToken,
mapboxgl: mapboxgl
});
document.getElementById('geocoder').appendChild(geocoder.onAdd(map));
</script>
点击搜索输入下方的地址会在地图上显示该位置。当我点击那个地址时,我想提醒地址的经纬度。我该怎么做?谢谢
我解决了我的问题。我写下任何人需要帮助的答案。
accessToken = 'xxxxxxxx';
var mapboxTiles = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=' + accessToken, {
attribution: '© <a href="https://www.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
tileSize: 512,
zoomOffset: -1
});
var map = L.map('map')
.addLayer(mapboxTiles)
.setView([39.525247, 34.160501], 6);
var geocoder = new MapboxGeocoder({
accessToken: accessToken,
mapboxgl: mapboxgl
});
document.getElementById('geocoder').appendChild(geocoder.onAdd());
geocoder.on('result', e => {
console.log(e.result)
})