【发布时间】:2019-03-08 09:05:35
【问题描述】:
我想要的是使用传单地图+功能,我可以传递纬度/经度并接收带有地址的短信。
我正在尝试使用 esri 插件,但是我做错了什么。 目前我很想得到函数内部的地址,但我不知道如何正确地将它传递给变量。
这是我的代码:
var map = L.map('map').setView([40.725, -73.985], 7);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var geocodeService = L.esri.Geocoding.geocodeService();
map.on('click', function(e) {
geocodeService.reverse().latlng(e.latlng).run(function(error, result) {
L.marker(result.latlng).addTo(map).bindPopup(result.address.Match_addr).openPopup();
});
});
var message;
message = geocodeService.reverse().latlng([40.725, -73.985]).run(function(error, result) {
//alert(result.address.Match_addr); //this alert works here ok and can retur addrress
return result.address.Match_addr;
});
//this alert won't work, why I can get the address here outside the function
alert(message);
这里是完整的例子: https://jsfiddle.net/5aq6z1vL/
如何使用地理编码器作为函数:
var address = convertToAddress([40.725, -73.985]);
function convertToAddress(]lat,lon])
{
// here return address after geocoding
}
【问题讨论】:
标签: javascript leaflet geocoding reverse-geocoding esri-leaflet