views:

656

answers:

3

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
but how i can get city, state.. what is the exact code.. or any function like getCity() ..
apueee
+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
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