Get address location from Latitude and Longitude in Google Maps

 Admin   
87 View    Dec 9 2020 6:43PM

 

 

Here Saber Shaikh has explained how to get the address location from Latitude and Longitude using the Google Maps Geocoding API.

 

In this article I will explain how to get the address location from Latitude and Longitude using the Google Maps Geocoding API.

i will Explain how to using the process of Geocoding using the Google Maps API.

Here we will pass the value of Latitude and Longitude directly from TextBox to the Google Maps API and it will return me the address of the location.

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    Latitude:
    <input type="text" id="txtLatitude" value="18.516726" />
    Longitude:
    <input type="text" id="txtLongitude" value="73.856255" />
    <input type="button" value="Get Address" onclick="GetGoogleAddress()" />
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
        function GetGoolgeAddress() {
            var lat = parseFloat(document.getElementById("txtLatitude").value);
            var lng = parseFloat(document.getElementById("txtLongitude").value);
            var latlng = new google.maps.LatLng(lat, lng);
            var geocoder = geocoder = new google.maps.Geocoder();
            geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[1]) {
                        alert("Location: " + results[1].formatted_address);
                    }
                }
            });
        }
    </script>
</body>
</html>
 
 
Reference : https://www.aspsnippets.com/Articles/Get-address-location-from-Latitude-and-Longitude-in-Google-Maps.aspx
 

Name
Comments