[LRUG] Geocoding and form submission

Andrew Stewart boss at airbladesoftware.com
Fri Apr 10 07:50:58 PDT 2009


On 10 Apr 2009, at 14:17, James Coglan wrote:
> Just realised I mis-read what Dan was saying, that the action that  
> processes the form submission on the server side should call the  
> geocoder if necessary before saving the record. Matter of fact, this  
> might be a better way to go if you can do it on the server, you  
> should only be using JS if you need some UI feedback for the  
> geocoding.

That's how I had planned to do it initially.  But then I read the  
documentation(!) and found that Google offers two geocoding services:  
one accessed with JavaScript and one via HTTP requests.  They say you  
should use the former for dynamic geocoding of user-defined addresses  
-- which is what I am doing in my app -- and the latter for geocoding  
static, known addresses.

Here's the documentation for the dynamic one (2nd paragraph):
http://code.google.com/apis/maps/documentation/services.html#Geocoding

And for the static one (3rd paragraph):
http://code.google.com/apis/maps/documentation/geocoding/index.html#Geocoding


> What I often do is put together a Google Maps widget that lets  
> people search for an address and drag a marker around, and this  
> saves the current marker position into some hidden form fields --  
> then the user gets accurate control of location data.

I hadn't thought about letting the user drag the marker around to get  
it just where they want...but it would solve the inaccurate geocoding  
problem.  It turns out that although Google geocodes most UK addresses  
as you would expect, a significant minority are off by a non- 
negligible margin.  Letting the user drag the marker around is exactly  
what I need.

Thanks!


> Still, the above code shows a useful technique known as  
> 'continuation passing style', where instead of returning a value  
> directly, each function takes a callback to call with the data when  
> it becomes available. It's really useful for combining async  
> functions without tightly coupling/duplicating bits of code.

It's been a while since I heard that phrase.  Thanks for the reminder  
-- it's a good technique.


Cheers,
Andy



More information about the Chat mailing list