问题描述
我正在使用 MapBox 地理编码,我想在控制台中打印创建的圆的坐标,但我不知道如何访问它。有人能帮我吗?不知何故,我必须访问我认为的结果,但我不知道我必须使用哪个命令。
var geocoder = new MapBoxGeocoder({
accesstoken: mapBoxgl.accesstoken,mapBoxgl: mapBoxgl,marker: false,zoom: 13
});
// After the map style has loaded on the page,// add a source layer and default styling for a single point
mymap.on('load',function() {
mymap.addSource('single-point',{
type: 'geojson',data: {
type: 'FeatureCollection',features: []
}
});
});
// Listen for the `result` event from the Geocoder
// `result` event is triggered when a user makes a selection
// Add a marker at the result's coordinates
geocoder.on('result',function(e) {
mymap.addLayer({
id: 'point',source: 'single-point',type: 'circle',paint: {
'circle-radius': 10,'circle-color': '#448ee4'
}
})
mymap.getSource('single-point').setData(e.result.geometry);
console.log(e.result.lngLat); /*this line*/
currentMarkers[0].remove();
});
document.getElementById('geocode').appendChild(geocoder.onAdd(mymap));
解决方法
您可以访问几何结果:
e.result.geometry.coordinates