Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the latitude and longitude of multiple addresses using Google API

I have a database of around 16000 records and i like to go through each address and get their latitude and longitude values.

I have tried exporting all records into excel sheet and then creat a macro to have a lat and lang values. It works for 80% of addresses, but google map api would return more results than Bing map as i have tried few addresses (which were not working with bing map) in google map and google is returning accurate values.

I like to use Google Map API to get latitude and longitude values as it has a limit of 25k requests per day.

I have got this java script which works fine but i don't know how can i use it with multiple addresses? I can loop through dataset but not sure if i need to call this java script function in the code behind page against every single address?

What is the best way to do this?

<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>
like image 578
user1263981 Avatar asked Dec 05 '25 13:12

user1263981


1 Answers

You would need to call this function for each address and then store the resultant long and lat. You would also need to throttle the requests (possibly using setTimeout()) as the API also has a rate limit. You can only make so many requests per second.

Bear in mind though that the storing and subsequent display of results from the geocoding service is against Google's TOS. You will be breaking the licence agreement without a paid subscription, under section 10.1.3 c.

(c) No Mass Downloads or Bulk Feeds of Content. You must not use the Service in a manner that gives you or any other person access to mass downloads or bulk feeds of any Content, including but not limited to numerical latitude or longitude coordinates, imagery, visible map data, or places data (including business listings). For example, you are not permitted to offer a batch geocoding service that uses Content contained in the Maps API(s).

I think 16k coordinates will certainly count as bulk.

like image 53
ChrisSwires Avatar answered Dec 08 '25 01:12

ChrisSwires



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!