That's what I thought at first, but here are some counter examples to
your claim of being able to get the same address from AddressDetails:

Manhattan, NY, USA (also contains "New York" as a
SubAdministrativeAreaName)
Dubai - United Arab Emirates (hyphen instead of comma)
Tramore, Co. Waterford, Ireland ("Co." appears nowhere in the
AddressDetails)


Matching on and removing the ThoroughfareName seems to work, but it
would have been nicer if I could have done something like specify a
GGeoAddressAccuracy in the call to geocoder.getLocations(). Another
non-elegant option is to display a message asking for a less specific
address if the GGeoAddressAccuracy is >= 6.

If anyone is interested, this is the code I used to get and strip the
ThoroughfareName (remember that the Lat, Lng points are still specific
to whatever address was requested).

----

var findVal = function(obj, attr) {
        // Depth first search (is fine in this case)
        if (typeof(obj[attr]) != 'undefined') { return obj[attr]; }
        var sub_attr, val;
        for (sub_attr in obj) {
                if (typeof(obj[sub_attr]) == 'object' && obj[sub_attr] !== 
null) {
                        val = findVal(obj[sub_attr], attr);
                        if (typeof(val) != 'undefined') break;
                }
        }
        return val;
}

if (Placemark.AddressDetails.Accuracy >= 6) {
        var streetName = findVal(Placemark, 'ThoroughfareName');
        if (streetName && Placemark.address.substring(0, streetName.length)
== streetName) {
                Placemark._address = Placemark.address;
                Placemark.address = Placemark.address.substring
(streetName.length).replace(/^[\s,\-]+/, '');
        }
}

On Jan 11, 6:05 pm, Andrew Leach <[email protected]>
wrote:
> On Jan 11, 4:52 pm, peter <[email protected]> wrote:
>
>
>
> > The best thing I can think of is to scan Placemark.AddressDetails for
> > a "ThoroughfareName" and then see if that matches the beginning of
> > Placemark.address and strip it off (plus any commas, hyphens).
>
> Placemark.address seems to be simply a concatenation of all the
> Placemark elements, so it's bound to match. In fact it will almost
> certainly be first, followed by a comma and a space -- I haven't
> tested that exhaustively though.
>
> Since it's bound to match, that would seem to be the easiest way to do
> it. The better way would be to ignore ThoroughfareName but concatenate
> all the other elements of the Placemark data yourself. That ends up
> being more complicated because different Placemarks have different
> constituent data and indeed different data structures: elements may or
> may not present, or may move in the hierarchy.
>
> Andrew
-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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-api?hl=en.


Reply via email to