Read Random Post

Tuesday, November 1, 2011

Get Address using latitude and longitude - Google Reverse GeoCode


<span id='addressObj'> </span>

<script type='text/javascript'>
     var geocoder = new google.maps.Geocoder(); 
     var myLatlng  = new google.maps.LatLng(00.0000, 00.0000); // put proper lat lon value
     var address;
     geocoder.geocode({'latLng': myLatlng}, function(results, status) { // getting address from latLong i.e latitude and longitude
     if (status == google.maps.GeocoderStatus.OK) { // If status is OK means address is found by server
              if (results[1]){
                   address = results[1].formatted_address;
                   document.getElementById('addressObj').innerHTML = address;
              } else {
                   document.getElementById('addressObj').innerHTML = status;
              }
      } else { // Otherwise it return address empty or undefined thats why we display status and latLong only
              document.getElementById('addressObj').innerHTML =  status;
      }
      });

</script>

Enhanced by Zemanta

0 comments: