繁体   English   中英

Google Maps api 3中的反向地理编码

[英]Reverse Geocoding in Google Maps api 3

我有以下Javascript代码,并且想对地图应用反向地址编码

这是我的JS代码

更新资料

 <script  type="text/javascript">
 var map;
 var geocoder;
 var markers = new Array();    
 function initialize() {
 geocoder = new google.maps.Geocoder(); 
 var GPS = <%=GPS %>
     var latlng = new google.maps.LatLng(31.2330555556,72.3330555556);
     var myOptions = {
      zoom: 7,
      scaleControl:true,
      pancontrol: true,
      streetViewControl: true,
      center: latlng,
      mapTypeControl: true,
      mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
      mapTypeId: google.maps.MapTypeId.HYBRID
    }    
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var infowindow = new google.maps.InfoWindow();      

    for(i=0; i<GPS.length; i++)
    {     
    //GeoCoding
      if (geocoder) {
      geocoder.geocode({'latLng': latlng}, function(results, status) 
      {
      if (status == google.maps.GeocoderStatus.OK) {
      if (results[1]) {                     
          markers[i] = new google.maps.Marker(
          { 
          position: GPS[i].GPS,
          map: map,
          draggable:true,    
          Info:  results[1].formatted_address,
          title:GPS[i].TITLE
           }
           }
           }
           });    
            google.maps.event.addListener(markers[i], 'click', function() {
            infowindow.setContent(this.Info);
            infowindow.open(map,this);
            });             

         }    
      }


</script>

先生,这是我的更新代码,我曾在其中编写过反向地理编码代码,但现在MU地图无法正常工作,请告诉我我确实缺少的内容

您已注释掉地址解析器,因此if语句对您而言永远不是真的。 您也已注释掉对codeLatLng的调用。

尝试取消注释,对于初学者!

更新:

您在信息框中没有具有期望ID的元素,地址和消息在哪里?

Info: '<table frame=box><tr>
<td align="Left">
<font face="Arial" size=2 color=#336699>Name:</td>
<td align="Left"><font face="Arial" size=2>'+ GPS[i].TITLE + '</font></td></tr><tr>'+
</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].CNT_TEH + '</font></td></tr>'+
              '</table>'

这确实是令人讨厌的html ..,但是请确保您有<span id='address'></span>或div也是一个用于发送消息的人。

还有<%= GPS%>呈现什么? 需要报价吗?

暂无
暂无

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

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