Ayo Softech

Tuesday 6 January 2015

Latitude Longitude in JavaScript by city

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></
script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function getLatLong() {
    var geocoder = new google.maps.Geocoder();
    var address = "New Delhi";//document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
       latitude = results[0].geometry.location.lat();
       longitude = results[0].geometry.location.lng();
       //alert(results[0].geometry.location.lat());
       //alert(results[0].geometry.location.lng());
       $("#locInfo").html("latitude="+latitude+" longitude="+longitude);
      }  else {
      }
    });
}
getLatLong();
</script>
<div id="locInfo" ></div>

1 comment: