How to cache server side geocodes

1,110 views
Skip to first unread message

Henri

unread,
Sep 9, 2011, 10:10:55 AM9/9/11
to Google Maps JavaScript API v3
Hi,

My webserver makes around 80% of the same geocodes everyday. Several
hundred a day wasn't a problem but now it is starting to get closer to
the 2.5k daily limit set by Google I wanted to know what the correct
way to cache server side geocode requests.

I've read this http://code.google.com/apis/maps/articles/geocodestrat.html#caching
but it did not explain how to actually cache the results. I am using
php/mysql and if anybody knows any good tutorials, documentation or
advice/knowledge on this subject I would really appreciate it.

Thanks in advance,
Henri

Barry Hunter

unread,
Sep 9, 2011, 1:32:37 PM9/9/11
to google-map...@googlegroups.com
Did you see this article?
http://code.google.com/apis/maps/articles/phpsqlgeocode.html

> --
> You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
> To post to this group, send email to google-map...@googlegroups.com.
> To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>

Mike

unread,
Sep 14, 2011, 10:41:25 AM9/14/11
to google-map...@googlegroups.com
Hi,

Thanks for the reply Barry but I couldn't find anything to help me cache the geocodes. The link also refers to gmaps v2, does that matter?

I was looking for the correct way to store geocodes, look up new geocodes not in the cache and using the cache for map searching or looking up lat/longs

Thanks 

Martin™

unread,
Sep 14, 2011, 11:13:44 PM9/14/11
to Google Maps JavaScript API v3
Hi.

How about first creating a MySQL table with columns 'md5', 'lat' and
'lng'.
'md5' will be a text type, 'lat' and 'lng' double type.

Now create the query string that your server will send to Google,
presumably something like:

$geocode_query='http://maps.googleapis.com/maps/api/geocode/json?
sensor=false&address=the_address_to_geocode';

Now create an md5 checksum of that query string using PHP's md5()
function:

http://php.net/manual/en/function.md5.php

Next query the database for a row with that md5 value.

No row in the database means you query Google and if the geocode
request is successful insert the result into the database.
Otherwise you can use the cached geocode result from the database.

Martin.
Reply all
Reply to author
Forward
0 new messages