【问题标题】:PinCode Null from Longitude and latitude Android Location Services来自经度和纬度 Android 定位服务的 PinCode Null
【发布时间】:2016-04-27 16:17:43
【问题描述】:

我正在尝试使用谷歌位置服务获取经度和纬度的密码。我使用地理编码器来获取地址对象。我看到某些地址 getPostalCode 为 Null,但在地址行中可以看到邮政编码。

在这种情况下如何获取邮政编码?我应该使用正则表达式来获取它吗?

【问题讨论】:

    标签: android google-maps geolocation


    【解决方案1】:

    基于此documentation,您需要使用componentRestrictions 参数指定限制,可以通过postalCodecountry 进行过滤。

    以下示例函数演示了使用componentRestrictions 参数按countrypostalCode 进行过滤:

    function codeAddress() {
    geocoder.geocode({
      componentRestrictions: {
        country: 'AU',
        postalCode: '2000'
      }
    }, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
        });
      } else {
        window.alert('Geocode was not successful for the following reason: ' + status);
      }
    });
    }
    

    你可以在 GitHub 上查看这个example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多