我想要的是使用 Leaflet maps + 功能,我可以通过 Lat/Lng 并接收带有地址的短信。
我正在尝试使用 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
}