I am geocoding multiple address from an XML file to get the lat/lng to plot a marker on a map. It works fine with about 15 addresses but today I checked and there are 88 addresses and it takes a while to load the page. What’s happening is a user clicks the link to the map page and the browser just spins until all the addresses have been geocoded, then the page loads. I’m having to use System.Threading.Thread.Sleep(150); before each call to the google service to avoid the query limit error. Is there anything I can do to make this load the page then load the addresses?
Share
As you’ve found, Google’s geocoding service isn’t for requests en masse. In fact, it’s against their terms of service to use the service for bulk downloads or processing batch requests.
What you ought to look for is a service that doesn’t have such low limits and allows you to submit batch requests to the API. For disclosure purposes, I work for SmartyStreets, and we provide such an API called LiveAddress.
It sounds like you’re submitting as many requests as there are addresses to geocode and plot. 15-100 requests will take anywhere from one to maybe 10 or 15 seconds including network latency. I’ve seen your situation quite a few times in my line of work and it’s a legitimate question.
What I’d recommend doing is having the server push down the page to the client, then have Javascript load the coordinates and plot the points. (C.Evenhuis suggested this in his comment.) While this will load the page earlier, it still should spin some sort of "Loading" animation, which will still make the user wait. Without an upgraded license with Google, your limits will remain.
To overcome this, you can look for an API that has a few key features:
You can use LiveAddress as an example of what to look for, and see if it meets your needs. It supports up to 100 addresses per single request, so your wait time goes from several seconds to a few milliseconds. You can store the results you download basically indefinitely, and will only return coordinates for addresses that actually exist, or it will fix addresses that aren’t quite correct. Let me know if you have any questions about it.
As a thought, even if you don’t want the client-side to geocode the addresses, your C# code can do this and bundle all the addresses into one request.
[Here’s some sample C# code on GitHub]