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..
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..
Share Improve this question edited Jul 17, 2009 at 7:01 RedBlueThing 42.5k17 gold badges98 silver badges122 bronze badges asked Jul 8, 2009 at 15:24 apueeeapueee 1162 silver badges11 bronze badges3 Answers
Reset to default 4Google 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;
}
}
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());
} });
http://code.google./apis/maps/documentation/services.html#ReverseGeocoding
geocoder = new GClientGeocoder();
...
geocoder.getLocations(latlng, showAddress);
(showAddress is a function)