繁体   English   中英

在谷歌地图上无法通过纬度和经度获得地址

[英]not geting address with help of lat and long in google map

我正在尝试使用reverse geocoding地址reverse geocoding来获取地址。
但是geocoder.geocode({...})行中存在一些问题。 即使是正常的警报消息也不会显示。

 function initialize() { 
 var mapOptions = { 
    zoom: 11,
    center: new google.maps.LatLng(23.0171240, 72.5330533),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);

  google.maps.event.addListener(map, 'click', function(e) {
    placeMarker(e.latLng, map);
    var input=e.latLng;
    var lat = parseFloat(input.lat());
    var lng = parseFloat(input.lng());
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
           alert(results[1].formatted_address);
        }
      });
    });
}

function placeMarker(position, map) {
  var marker = new google.maps.Marker({
    position: position,
    map: map
  });
  map.panTo(position);
}

google.maps.event.addDomListener(window, 'load', initialize);

在initialize()函数中添加以下行。

var geocoder = new google.maps.Geocoder();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM