开发者

Google Map GetLocation Return String

开发者 https://www.devze.com 2023-03-16 21:04 出处:网络
I have this piece of code , geocoder = new GClientGeocoder(); var state; function addAddressToMap(response) {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号