简体   繁体   中英

Reverse Geocoding in Google Maps api 3

I Have Following Javascript Code And I want to Apply Reverse Geocoding For My map

Here is My JS Code

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

You have commented out geocoder, so it is never is true in you if statement. You have also commented out the call to codeLatLng.

try uncommenting them, for starters!

UPDATE:

You dont have elements with the ids you expect in your infobox, where are address and message ?

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.

Also what does <%= GPS %> render to? dose it need to be quoted?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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