2009-07-08 8 views
2

私は場所を表示するためにGoogleマップAPIを使用しています。その場合私はGoogleマップマーカーから都市のシテジップを取得するオプションが必要です。地図では、ドラッグが終了した後、マーカを移動して都市、州、およびジップを返します。私は首尾よく緯度と経度を取得しましたが、どのように都市、州、およびジップを得ることができます。できるだけ早く私を助けてください..Googleマップから街の状態を取得

答えて

4

Google MapsのAPIは、特定のアドレスのデータを抽出するためにrather verbose formatを使用しています。

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; 
    } 
} 
1

Javascriptの方法についてはあまり確かではありませんが、GWT Googleマップライブラリを使用して同じように行っています。

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()); 
    } }); 
関連する問題