Tik*_*kky 5 javascript geocoding reverse-geocoding leaflet esri-leaflet
我想要的是使用传单地图+功能,我可以在其中传递纬度/经度并接收带有地址的短信。
我正在尝试使用 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); 
Run Code Online (Sandbox Code Playgroud)
这是完整的示例: https: //jsfiddle.net/5aq6z1vL/
如何将地理编码器用作如下函数:
var address = convertToAddress([40.725, -73.985]);
function convertToAddress(]lat,lon])
{
  // here return address after geocoding
}
Run Code Online (Sandbox Code Playgroud)
    |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           8494 次  |  
        
|   最近记录:  |