【问题标题】:get city state from google map从谷歌地图获取城市状态
【发布时间】:2010-11-09 02:05:24
【问题描述】:

我正在使用 google map api 来显示位置。在这种情况下,我需要选择从谷歌地图标记获取城市邮政编码。在地图中,用户可以在拖动完成后移动标记来定位它,它将返回城市、州和邮政编码。我已成功获取 lat 和 lng,但我如何获取城市、州和邮政编码。请尽快帮助我..

【问题讨论】:

    标签: php javascript google-maps


    【解决方案1】:

    不太了解 Javascript 方式,但我使用 GWT Google Maps 库也做过类似的事情

    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());
        } });
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        http://code.google.com/apis/maps/documentation/services.html#ReverseGeocoding

        geocoder = new GClientGeocoder();
        ...
        geocoder.getLocations(latlng, showAddress);
        

        (showAddress 是一个函数)

        【讨论】:

        • 但是我怎样才能得到城市、州......确切的代码是什么......或者像 getCity() 这样的任何函数......
        猜你喜欢
        • 2017-10-25
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 2016-12-07
        • 1970-01-01
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多