我正在使用谷歌地图地理编码器对邮政编码进行地理编码,我希望它返回邮政编码所在的状态并将其存储在变量“local”中。我收到一个错误,表明本地未定义。为什么?
见下面的代码:
var address=document.getElementById("address").value;
var radius=document.getElementById("radius").value;
var latitude=40;
var longitude=0;
var local;
geocoder.geocode( { 'address': address}, function(results, status){
if (status==google.maps.GeocoderStatus.OK){
latlng=(results[0].geometry.location);
latitude=latlng.lat();
longitude=latlng.lng();
//store the state abbreviation in the variable local
local=results[0].address_components.types.adminstrative_area_level_1;
}
else{
alert("Geocode was not successful for the following reason: " + status);
}
});