I’ve been having quite a bit of trouble with Google Maps API and a database driven map. In a previous question I had inquired about faster geocoding of addresses to a map and basically what I need to do is store Lat/Lng into the database and create a map from there, instead of geocoding while the map is loading.
However, I’m unsure exactly how to do this. I know the basic premise – 1) User registers and enters in their address. 2) Database should store the user’s information, along with the address. 3) Address needs to be geocoded and then added to the Lat/Lng fields in the database. 4)Markers can then be placed on the map by looping through a query involving the Lat/Lng fields.
Any ideas how to do this? I’m using ColdFusion, SQL Server.
You can use Google’s Geocoding Service for this. The API is dead simple. You send an address in the url and it returns some xml with the geocoded result. Even better, there’s a project on RiaForge called Google Geocoder v3 that will do all the work for you.
Here’s some sample code of the CFC:
As for when to do the geocoding, you have two options. One is just to do it when they register – take the address from the registration form, call the geocoding service to get the lat/lng and then save everything to the database. The other option is to save the address from registration and then have a separate scheduled task to periodically checks and geocodes any un-geocoded addresses.