javascript - Reverse Geocode on Client Side (Google Maps V3 API) -


how do reverse geocode on clientside using google maps v3 api? forward geocode address latlng straight forward (code below), how do same reverse geocode?

normal geocode code:

geocoder = new google.maps.geocoder(); geocoder.geocode( { 'address': address}, function(results, status) {   if (status == google.maps.geocoderstatus.ok) {     map.setcenter(results[0].geometry.location);     var marker = new google.maps.marker({     map: map,     position: results[0].geometry.location   }); 

the process same, minor difference instead of supplying address object geocode function supply latlng object

reverse geocode code:

var input = document.getelementbyid("latlng").value; var latlngstr = input.split(",",2); var lat = parsefloat(latlngstr[0]); var lng = parsefloat(latlngstr[1]); 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       });        infowindow.setcontent(results[1].formatted_address);       infowindow.open(map, marker);     } else {       alert("no results found");     }   } else {     alert("geocoder failed due to: " + status);   } }); 

example directly google

hope helps.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -