Get Latitude Longitude Using Google API

Below is the very simple code which can be helpful to get the latitude longitude using Google Map API. 
 
First you need to include below js, which can be found on internet.
  1. jquery.min.js
  2. jquery-1.7.2.min.js
Javscript script to call Google Map API 
  1. <script lang="javascript" type="text/javascript">  
  2.        function FindLocaiton1(address) {  
  3.            var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&sensor=false';  
  4.            $.ajax  
  5.            ({  
  6.                url: url,  
  7.                data: 'json',  
  8.   
  9.                success: function (results, xhr) {  
  10.                    $.getJSON(url, function (results) {  
  11.                        
  12.                        d1.innerHTML = "Loading ...";  
  13.                        for (var k = 0; k < results.results.length; k++)  
  14.                        {  
  15.                            if (k == 0)  
  16.                                d1.innerHTML = "";  
  17.                            d1.innerHTML = d1.innerHTML + "<br/>" + (k + 1) + ". Lat : " + results.results[k].geometry.location["lat"] + ", Long: " + results.results[k].geometry.location["lng"] + " >> Area : " + results.results[k].address_components[2].long_name + "<hr/>";  
  18.                        }  
  19.                      
  20.                    });  
  21.                }  
  22.            });  
  23.        }  
  24.    </script>  
To call the above function use below code.
  1. <input id="b1" type="button" runat="server" value="Find Location" onclick="FindLocaiton1(t1.value);" />  
  2.        <div id="d1">  
  3.        </div>  
Simple, just run this code and you will get the Latitude Longitude based on any available address on earth.
 
Hope it helps someone.
Ebook Download
View all
Learn
View all