function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
steve_andersensteve_andersen 

Google geocoding API

I want to hit google's geocoding api from an @future class on a trigger so I can add lat and lon to records as they change. I have a couple questions:
  1. If I want to hit the rest interface for google's service, I need to supply an api key. Do I need to do anything special to get that key to work from salesforce.com servers? It asks me to identify the calling domain--should that be salesforce.com?
  2. The API will respond to one call every 2 seconds, equating to 50,000 calls a day. What's the best way to deal with that limiter in an apex class? I couldn't find a sleep function.
Thanks,
Steve
Luke@TWSLuke@TWS
1. Give it a go and see if salesforce.com works, I've only tried na1.salesforce.com but that works fine.
2. Could possibly try just looping till the service doesn't return an error. It's dirty but could work. Other than that look into alternate geocoding services?
steve_andersensteve_andersen
After talking offline to Ron Hess here are some thoughts:
  1. There is no sleep function in Apex--I understand why they don't want my processes hanging out on their sever--so you can't time something like this from a class.
  2. Google gives you a 620 error if you hit the server too soon after your last hit. If you get this error, you could flag the record to be geocoded at a later date, probably from a VisualForce page because...
  3. You can do timing from a VisualForce page with the Action Poller control, so you could queue up 100 records and geocode them every 2 seconds
  4. Like Luke, Ron hasn't had any problems geocoding from salesforce.com servers. We'll see what happens as more and more folks hit google from salesforce ip addresses
Steve
Luke@TWSLuke@TWS
That's the problem when trying to use something that's free. Hopefully one day the google salesforce thing will allow more usage of the services.

If you're willing to pay a bit you can easily find a service that will allow unlimited lookups and get around all of the problems in one go.
GoForceGoGoForceGo

Given the constraint of working with a free service like google, how do you automate this process:

 

1. If you put a trigger with @future, the trigger can handle no more than batch of 10 contacts, since callout limit is 10 for Apex. Further Google won't do all 10 of them - I see it do only first 2-3 and then start giving 620 message. There is no delay in Apex.

 

2. If you do it from a Visual Force page with an action poller, you have to manually start it.


So if my org has contacts being added on a constant basis with batch load, I will miss out batches that are > 10.

 

Someone would have to manually run the VF page...

 

 

Message Edited by GoForceGo on 03-11-2009 11:36 AM