使用传单 esri 插件从数据库中对地址名称进行地理编码
Geocoding Address name from Database using leaflet esri plugin
我正在尝试构建一个在数据库中使用地址名称并在传单地图中显示标记的地图应用程序。我遇到过传单 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
下面是一个使用 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();
});
我正在尝试构建一个在数据库中使用地址名称并在传单地图中显示标记的地图应用程序。我遇到过传单 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
下面是一个使用 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();
});