2016-04-27 55 views
0

我想通过谷歌定位服务获取经纬度pincode。我使用geocoder来获取地址对象。我看到在某些地址getPostalCode为空,但可以在地址行中看到邮政编码。PinCode Null来自经纬度Android位置服务

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

回答

0

根据此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); 
    } 
}); 
} 

您可以检查此example在GitHub上。