简体   繁体   English

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

[英]Reverse Geocoding in Google Maps api 3

I Have Following Javascript Code And I want to Apply Reverse Geocoding For My map 我有以下Javascript代码,并且想对地图应用反向地址编码

Here is My JS Code 这是我的JS代码

Update 更新资料

 <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>

Sir This Is My Updated Code Where I have wrote the Code for Reverse Geocoding But Now MU map Is not Working Please tell me WHAT Exactly I am Missing 先生,这是我的更新代码,我曾在其中编写过反向地理编码代码,但现在MU地图无法正常工作,请告诉我我确实缺少的内容

You have commented out geocoder, so it is never is true in you if statement. 您已注释掉地址解析器,因此if语句对您而言永远不是真的。 You have also commented out the call to codeLatLng. 您也已注释掉对codeLatLng的调用。

try uncommenting them, for starters! 尝试取消注释,对于初学者!

UPDATE: 更新:

You dont have elements with the ids you expect in your infobox, where are address and message ? 您在信息框中没有具有期望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>'

This is truly nasty html.. but make sure you have <span id='address'></span> or a div also one for message. 这确实是令人讨厌的html ..,但是请确保您有<span id='address'></span>或div也是一个用于发送消息的人。

Also what does <%= GPS %> render to? 还有<%= GPS%>呈现什么? dose it need to be quoted? 需要报价吗?

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

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