【发布时间】:2014-01-23 20:45:30
【问题描述】:
我正在使用地理编码器根据邮政编码获取位置(我将其限制在美国)。一切正常,除了如果我输入了一个无效的 zip(例如 90123),它会给我一个默认值而不是给ZERO_RESULTS。默认值恰好是德克萨斯州丹顿(对于所有无效代码)。如何防止这种情况发生,或判断代码是否无效以避免此问题?
我正在使用此代码:
geocoder.geocode({ 'address': zip, componentRestrictions: {country: 'us'} }, function (results, status) {
if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
jQuery('#zipErrorId').html("INVALID");
}
if (status == google.maps.GeocoderStatus.OK) {
geocoder.geocode({'latLng': results[0].geometry.location}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var cityState = getCityState(results);
// like Apple Valley, Minnesota
var cityStateArr = cityState.split('|');
---------------------------
}
}
});
}
【问题讨论】:
标签: zip geocoding google-geocoder