I have this piece of code ,
geocoder = new GClientGeocoder();
var state;
function addAddressToMap(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
}
else {
place = response.Placemark[0];
state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
}
}
// showLocation() is called when you click on the Search button
// in the form. It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = "mutiara damansara";
geocoder.getLocations(address, addAddressToMap);
return state;
}
Alright , updated the codes . I try to instantiate showLocation() , but the variable state isn’t being updated by addAddressToMap function .
Thanks
Your updated code helps see the picture a little better.
It looks like
addAddressToMap()is expecting a response variable from the function arguments.When it’s called by
geocoder.getLocations(address,addAddressToMap)there’s no response passed.So, the first
ifstatement!responseis true, andstateremains unset.To fix, you need to pass something when you call
addAddressToMap(). It looks like that something is anXMLHttpRequest(Ajax) object from somewhere else in the script.