Google Map GetLocation Return String
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 if
statement !response
is true, and state
remains unset.
To fix, you need to pass something when you call addAddressToMap()
. It looks like that something is an XMLHttpRequest
(Ajax) object from somewhere else in the script.
精彩评论