0
我使用地理編碼器來獲得一個基於郵政編碼的位置(我限制它只是美國)。一切工作正常,除非如果我輸入一個無效的zip(例如90123),它給了我一個默認值,而不是給ZERO_RESULTS
。默認值恰好是德克薩斯州的Denton(對於所有無效代碼)。我怎樣才能防止這種情況發生,或者告訴一個代碼是否無效以避免這個問題?GeoCoder給出了無效的郵政編碼的默認值
我使用這個代碼:
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('|');
---------------------------
}
}
});
}