我正在尝试建立一个地图应用程序,使用数据库中的地址名称和在传单地图中显示标记。我遇到了leaflet esri插件,但不确定如何使用代码。谁能教我如何从地理编码函数中提取结果(经度和纬度)并绘制标记?谢谢!
地理编码函数:
L.esri.Geocoding.geocode(<Object> options)结果:
{results: [
{
latlng: L.LatLng,
text: 'Formatted Address',
score: 100, // certainty ranking of the match
properties: {
// additional info like specific address components (Country Code etc.)
}
}
]
}http://esri.github.io/esri-leaflet/api-reference/tasks/geocode.html
发布于 2018-12-24 03:14:59
下面是一个使用ES6的示例:
import L from "leaflet";
// import library as ELG
import * as ELG from "esri-leaflet-geocoder";
// here is an example address in the US - use the one from your DB
const address = "380 New York St, Redlands, California, 92373";
// call geocode method of the library, no need to call L.esri.Geocoding.geocode() as in vanilla js
ELG.geocode()
// pass the address
.text(address)
.run((err, results, response) => {
console.log(results.results[0].latlng);
// retrieve latitude, longitude from related response
const { lat, lng } = results.results[0].latlng;
// build a marker using the retrieved address
L.marker([lat, lng])
.addTo(mymap)
.bindPopup(address)
.openPopup();
});https://stackoverflow.com/questions/53894242
复制相似问题