Function to determine latitude and Longitude
Permalink Browser Info Environment
I am feeding some map data in manually through a custom script and this is working great. However my map data has address information, but does NOT have latitude and longitude. In looking at the way you set it up for adding items, it seems that the system looks up the latitude and longitude when you add in the address during the form entry and stores it (smart!).
Before I searched much more I was wondering if there was a code snippet you used that you could point me to that I could reuse to look up lat/long when I am manually inserting data into the table - as you do upon form entry.
Thanks for any help you can provide.
Before I searched much more I was wondering if there was a code snippet you used that you could point me to that I could reuse to look up lat/long when I am manually inserting data into the table - as you do upon form entry.
Thanks for any help you can provide.
Type: | Pre-Sale |
---|---|
Status: | Resolved |
Oh great, I was actually just writing you a reply - did you still need some suggestions here, or are you all sorted?
The main point I was going to say is that this addon uses the Javascript API (so you don't need two different keys), whereas if you are doing more of a server based import you'd likely need different code.
The main point I was going to say is that this addon uses the Javascript API (so you don't need two different keys), whereas if you are doing more of a server based import you'd likely need different code.
That looks like the javascript API anyway now that I look at it - that should be all you need to do then really.
Just be aware of the 50 per second limit, quite easy to hit!
Just be aware of the 50 per second limit, quite easy to hit!
Ah good call I've got about 200 to process - do you know how long I need to pause between sets of 50 or so?
I think only a second
There's also a 2500 per day limit I believe, easy to hit too if you do the import a few times
There's also a 2500 per day limit I believe, easy to hit too if you do the import a few times
Any case anyone needs the code:
$geoaddress = $address .", CO, " . $zipcode . ", United Sates"; //Address //slow down if needed if ($totalcount > 45) { sleep(5); $totalcount = 0; } // Get JSON results from this request $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($geoaddress).'&sensor=false'); $geo = json_decode($geo, true); // Convert the JSON to an array if (isset($geo['status']) && ($geo['status'] == 'OK')) { $latitude = $geo['results'][0]['geometry']['location']['lat']; // Latitude $longitude = $geo['results'][0]['geometry']['location']['lng']; // Longitude }
https://gist.github.com/madeinnordeste/3250820...
Working well.