1

我不确定我的问题是否有效。但我有一些要求,如下所示。

是否有可能获得具有特定latand的地点对象lng

详细来说,当我们使用自动完成方法时,我们可以得到如下地点对象:
"place = autocomplete.getPlace();"

getPlace()是否可以为特定latlng或任何其他可用的解决方案调用方法?

4

1 回答 1

1

准确地说,您要问的是所谓的Reverse Geocoding

维基

反向地理编码是将点位置(纬度、经度)反向(反向)编码为可读地址或地名的过程。

是的,谷歌提供反向地理编码服务。 但这不是您在问题中提到的一行。

它有自己的程序。

查看谷歌的反向地理编码了解更多信息。

您可能会发现以下代码很有用。

var geocoder;
var map;
function initialize() {
  geocoder = new google.maps.Geocoder();  //  * initialize geocoder class
  var latlng = new google.maps.LatLng(40.730885,-73.997383);
  var mapOptions = {
    zoom: 8,
    center: latlng,
    mapTypeId: 'roadmap'
  }
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}

function getPlace() {    
  var lat = your Latitude;   // give valid lat
  var lng = your Longitude;  // give valid lng
  var latlng = new google.maps.LatLng(lat, lng);
  geocoder.geocode({'latLng': latlng}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        map.setZoom(11);
        marker = new google.maps.Marker({
            position: latlng,
            map: map
        });
      }
      else {
        //handle error status accordingly
      }
    }
  }
}
google.maps.event.addDomListener(window, 'load', initialize);

希望你能理解。

于 2013-08-06T12:40:41.540 回答