views:

45

answers:

2

What is the best way to plot points on a Google map? I have a bunch of addresses (about 300) stored in my database, and right now I am outputting each address into a JS array and plotting each address by looping over the array and running a function that geocodes the address and creates a new marker. However, I'm not sure if that is the best approach. Any thoughts?

+2  A: 

Your problem is the geocoding part. Geocoding 300 addresses in one go is slow, and you would quickly hit the daily limit.

You should consider doing the geocoding on the server-side, and caching them in your database, or somewhere else. The Google Maps API Terms of Use appear to permit the caching of geocoding results "for the purpose of improving the performance of your Maps API Implementation" (Section 10.3).

Daniel Vassallo
What would be a good server-side geocoding API then? Also, once i have geocoded all the addresses via another API, would it be fine to just output all the lat/longs into a JS array and run a function that loops over the array and plots each one?
phpguy
@phpguy: Google offers a very good (and popular) server-side Geocoding API: http://code.google.com/apis/maps/documentation/geocoding/. Yep, then just build a JavaScript array of lat/longs as you suggest, like this: http://stackoverflow.com/questions/3723092/adding-multiple-markers-on-google-map-using-api-v2/3723119#3723119 (Using v2 API, but easily convertible to v3).
Daniel Vassallo
+1  A: 

If the addresses are relatively constant, then the repeated geocoding isn't terribly efficient. You could geocode each once and submit to Google Maps only the latitude and longitude for plotting. See the KML upload information.

wallyk