To access the address result with "types" "country" requires that you
step through the array of address components. Why? You cannot tell
in advance which address components are available. (Though "country"
is almost always available, you still don't know where it will be in
the array.)
This is not difficult:
for (var componentsIndex in results[0].address_components) {
if (results[0].address_components[componentsIndex].types[0] ==
'country' ) {
alert('Country name: ' +
results[0].address_components[componentsIndex].long_name);
}
}
[not tested, but believed to have been typed correctly]
- jeff
On Apr 1, 11:37 am, JFrancis <[email protected]> wrote:
> In the version 2 API, you could get to those individual elements this
> way:
>
> var place = response.Placemark[0];
> var point = new GLatLng(place.Point.coordinates[1],
> place.Point.coordinates[0]);
>
> myAddress =
> place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Local
> ity.Thoroughfare.ThoroughfareName
>
> myCity =
> place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Local
> ity.LocalityName
>
> myState =
> place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName
>
> myZipCode =
> place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Local
> ity.PostalCode.PostalCodeNumber
>
> Sadly, I have not seen an equivalent method of retrieving that
> information in the v3 API. The only solution I have seen which does
> not require yet ANOTHER Javascript library was posted here:
>
> http://stackoverflow.com/questions/5341023/retrieving-postal-code-wit...
>
> Not a very elegant solution to something which should have been
> carried forward.
>
> -- JF
--
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.