2013-08-06 19 views
0

我不确定我的问题是否有效。但是我有如下的一些要求。是否可以使用特定的lat和lng获取地点对象?

是否有可能获得具体的latlng的地方对象?

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

是否可以拨打getPlace()特定方法latlng或任何其他解决方案?

回答

1

准确地说,你要求的是叫做反向地理编码

维基

反向地理编码是回(反向)编码的点 位置(纬度,经度)的一个可读的地址或地名的过程。

是Google提供反向地理编码服务。 但这不是你在你的问题中提到的单一行。

它有自己的程序。

检查Google's 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); 

希望你的理解。

+0

感谢您的快速回放,希望它对我有帮助。 – Jaison

+0

@ user1374554我很高兴能够提供帮助。 – Praveen

相关问题