How to get Latitude and longitude based on address in Asp.Net


Here we will see How to get Latitude and longitude based on address in Asp.Net.

HTML CODE:
<div>
        <textarea id="txtAddress" rows="3" cols="25"></textarea>
        <br />
        <input type="button" onclick="GetLocation()" value="Get Location" />
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA-Dvf0kFAG9y2vRvkhbRy-obcU_wtSh3U&sensor=false"></script>
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">
            function GetLocation() {
                var geocoder = new google.maps.Geocoder();
                var address = document.getElementById("txtAddress").value;
                geocoder.geocode({ 'address': address }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var latitude = results[0].geometry.location.lat();
                        var longitude = results[0].geometry.location.lng();
                        alert("Latitude: " + latitude + "\nLongitude: " + longitude);
                    } else {
                        alert("Request failed.")
                    }
                });
            };
        </script>
    </div>

Related Posts

Previous
Next Post »

1 comments:

comments
February 4, 2022 at 8:27:00 AM GMT+5:30 delete

kalo sebalik nya bagaimana tanpa KEY

Reply
avatar

Thanks for comments.....