Hey guys!
I'm trying to use the reverse geocoder to update the fields in a
form.
so the user has a marker, he moves this marker and the street,city,
country and zip fields get automatically populated if the geocoder is
able to resolve this address.

I have this code here:
geocoder.geocode({
                        'latLng': latlng
                }, function(results, status) {
                        var streetNumber = '';
                        var streetName = '';
                        var country = '';
                        var postalCode = '';
                        var city = '';
                        if (status == google.maps.GeocoderStatus.OK) {

                                results[0].address_components.each(function(el) 
{

                                        el.types.each(function(type) {
                                                if(type == 'street_number') {
                                                        streetNumber = 
el.long_name;
                                                }

                                                if(type == 'route') {
                                                        streetName = 
el.long_name;
                                                }

                                                if(type == 'country') {
                                                        country = el.long_name;
                                                }

                                                if(type == 'postal_code') {
                                                        postalCode = 
el.long_name;
                                                }

                                                if(type == 'locality') {
                                                        city = el.long_name;
                                                }

                                        })
                                });

                                document.id('street').set('value', streetName + 
streetNumber);
                                document.id('zip').set('value', postalCode);
                                document.id('town').set('value', city);
                                document.id('country').set('value', country);
                        }
                });

Now I'm using the first result in the response, because I think that
it is always most accurate. Then I look for the type of each
address_components and map it to my variables.

Moving the marker around in spain seems to give me the proper results.
For example if I place the marker over Palma de mallorca - the
locality is Palma de Mallorca. If I go over Barcelona, then the
locality is Barcelona.

Now when I go over London, England I get really confusing results.
Instead of the city being London, the geocoder tells me that it is
either great london, lambeth or another boroughs of london.

There is one area of 1-2 square km that is mapped to London,
everything else is not london for the geocoder.

So my question here is - am I supposed to look for the city/zip/street/
country the way I do it or is there another way that will give me the
results I want?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to