I am using google maps geocoder to geocode a zipcode and I want it to return the state that the zipcode is located in and store it in the variable "local". I am getting an error indicating that local is undefined. Why?
see code below:
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);
}
});