I'm using google map api for showing location. In that i case i need option to get city sate zip from google map marker. In map , user can move the marker to position it after drag finished it will return the city, state and zip. I have successfully get the lat and lng but how can i get the city , state and zip. please help me as soon as possible..
A:
http://code.google.com/apis/maps/documentation/services.html#ReverseGeocoding
geocoder = new GClientGeocoder();
...
geocoder.getLocations(latlng, showAddress);
(showAddress is a function)
larson4
2009-07-08 15:28:48
but how i can get city, state.. what is the exact code.. or any function like getCity() ..
apueee
2009-07-08 15:40:55
+2
A:
Google Maps API uses a rather verbose format to extract specific address data:
geocoder.getLocations(latlng, showAddress);
function showAddress(response){
if (response && response.Status.code == 200){
var place = reponse.Placemark[0]
var city = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
var state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
var zip = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;
}
}
Triptych
2009-07-08 15:43:07
A:
Not too sure about Javascript way, but I have done the same using GWT Google Maps library like this
geocoder.getLocations(<<Your Address>>, new LocationCallback() {
public void onFailure(int statusCode) {
Info.show("Failed","Unable to geocode that address.","");
}
public void onSuccess(JsArray<Placemark> locations) {
final Placemark place = locations.get(0);
Window.alert(place.getCity() + place.getState() + place.getCountry() + place.getPostalCode());
} });
subh
2010-05-07 15:14:50