javascript - Google Map GetLocation Return String -
i have piece of code ,
geocoder = new gclientgeocoder(); var state; function addaddresstomap(response) { if (!response || response.status.code != 200) { alert("sorry, unable geocode address"); } else { place = response.placemark[0]; state = place.addressdetails.country.administrativearea.administrativeareaname; } } // showlocation() called when click on search button // in form. geocodes address entered form // , adds marker map @ location. function showlocation() { var address = "mutiara damansara"; geocoder.getlocations(address, addaddresstomap); return state; }
alright , updated codes . try instantiate showlocation()
, variable state
isn't being updated addaddresstomap
function .
thanks
your updated code helps see picture little better.
it looks addaddresstomap()
expecting response variable function arguments.
when it's called geocoder.getlocations(address,addaddresstomap)
there's no response passed.
so, first if
statement !response
true, , state
remains unset.
to fix, need pass when call addaddresstomap()
. looks xmlhttprequest
(ajax) object somewhere else in script.
Comments
Post a Comment