Friday, March 5, 2010

Client-Side Geocoding Rocks!

Part of my job is to help partners with their code, making sure they are successfully implementing on Google Earth and Maps. The most common problem people come to me with is something like "Can you give me more quota, my http geocoding limit is reached." This is for the free Google Maps API. There's a simple solution. Don't do it!

The way the quota for the Google Maps API geocoder works is by IP address. If you put the geocoder in your JavaScript code (or Flash) it's rendering in the browser. And therefore counts against the IP address quota of the browser, not your site. If you have a single server side script that does an IP address lookup, it's going to be against the single IP address of the server. In other words, if your site is popular, you're going to run out quickly.

So, geocode in the browser and then send the geocode to do your lookup. We even allow for caching, as long as you're going to display on a Google Map or Google Earth. Caches can happen in the browser or server side.

A few additional things to think about:
1) Cloud computing services often share a range of IP addresses. If you're running on AWS or Google App Engine or any other cloud computing service, you particularly want to do client side geocoding, as you may be running quotas parallel to other apps.

2) Some mobile networks share IP addresses as well. That can cause problems for your client side software, as lots of people on their smart phones are looking at your map. If you anticipate heavy mobile use, you might consider having a server-side back-up as a fail-over. Try to geocode and if that doesn't work, send the address to your server for http geocoding.

3) If you're still running into problems with quota, you may consider a Maps API Premier license. Check out http://maps.google.com/getmaps for more information on the differences and to get started.


14 comments:

Neil said...

I want to find objects such as Mosques, Hotels, Restraunts using geocoding is it possible....I don't have address for that just the google maps service is it possible.

Please reply for my mails.

Mano Marks said...

Neil, You can use our Ajax Search API:
http://code.google.com/apis/ajaxsearch/local.html

You can also just use Google Maps and Earth and search, it'll show you whatever is close by.

Unknown said...

Mano, great article and tips, thanks.

Do you know if there are any less expensive tiers of service for Maps Premiere? I know it may be a hard business decision but speaking to other devs in the industry, the $10K price point is quite steep for us startups.

Thanks again for the tips.

Mano Marks said...

Sheridon, not at this point, no.

Elad Katz said...

Hi Mano, please check out the discussion at http://groups.google.com/group/google-maps-js-api-v3/browse_frm/thread/58bee37631e3a366/b220663ed0dc6fbe#b220663ed0dc6fbe
it is about this subject and points out a problem with this method and the guys on your end say that what you're describing is not an intended use case.
please help by straightening this out.
Thanks,
e.

Mano Marks said...

@Elad these two positions are not contradictory. While it may not be an intended use case for JavaScript geocoding, the low quotas for http geocoding make it a necessity for data driven applications. I'll check with Ben to make sure there's not a real contradiction, but I don't think these are fundamentally different.

Vincent said...

Hi,
""geocode in the browser and then send the geocode to do your lookup. We even allow for caching""

Any chance of some coded example of do this please?
Looked everywhere for 2 days :-(

Davoscript said...

Hello Mano, in first place thank you for your contribution, being more than 3 years old it still is very useful.

I have a few doubts about how the client-side geocoding works in this cases:

1) Making an "ajax" request to "http://maps.googleapis.com/maps/api/geocode/json?address=...." doesn't count as a client-side geocodificatio (as it uses the http service)?

2) If I use the "new google.maps.Geocoder()" in my JS I'm automatically sending request using the web-app visitor's IP (client-side geocoding)?

3) I've looked everywhere and I haven't found the "per sessions limits" for client-side geocoding.

Thank you again for your contribution and I hope you still take a look at this blog.

Best Regards,
David.

Mano Marks said...

Indeed, this post is 3 years old and slightly out of date. This is slightly more recent and more official:
Geocoding Strategies.

You can also get lots of answers to questions on StackOverflow.

To address your points specificially:

1) That's not the intended use for the Geocoding API, you'll have been integration with the JS Maps API geocoder.

2) Yes

3) This is an IP address limit, not a session limit

Davoscript said...

Mano, it's me again, hope I'm not a pain :P

I'm just stuck here with the point "3" of my previous post, you told me that it is a IP-limit, however I found this other info in the link you gave me: https://developers.google.com/maps/articles/geocodestrat#client

"As geocoding limits are per user session, there is no risk that your application will reach a global limit as your userbase grows. Client-side geocoding will not face a quota limit unless you perform a batch of geocoding requests within a user session. Therefore, running client-side geocoding, you generally don't have to worry about your quota."

I'm kinda confused here and I certainly couldn't find other developers answers about this "sesion" or the real limits, except for the 2,500 a day map renderings from the serverside geocoding.

Best regards and thanks a lot for your time! :)

Davoscript said...

Correction: "except for the 2,500 a day geocoding requests"

Mano Marks said...
This comment has been removed by the author.
Mano Marks said...

Sorry, looks like it has been redefined to session. Unfortunately we don't provide a definition of a session. However, it should get you 2500 per day. Geocoding using the web service is by IP address.

Davoscript said...

Thank you Mano!

Not knowing exactly what a "session" is and its limits isn't the ideal scenario, however I understand that the main idea behind the "client geocoding" strategy is to help developers who make a good use of the API, so I'll stick to this:

"As geocoding limits are per user session, there is no risk that your application will reach a global limit as your userbase grows."

Thank you for your help and time.

PS: Is there any way to keen in touch & colaborate with you (you have a newer blog or something?) ? We've been doing some cool stuff here in with Google Maps for an important non-profit ONG here :)

Best Regards,
David.