Hi everybody.
I have a GMaps application (using GMAP API v3) that take from a DB the
adresses of the users (zip code, State) and geocode these. The problem
now is that in the callback function inner the geocode method I want
to modify a global variable, but since the geocode method is an
aynchronous call to the server, the global variable it will not be
updated.
very simple example:
var geocoder;
var latlng; // the variable I want to update
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
loadMap(address);
var myOptions = {
zoom: zoom,
center: latlng, //the variable it wont
be updated
from loadMap
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new
google.maps.Map(document.getElementById
("map_canvas"), myOptions);
}
function loadMap(address){
geocoder.geocode( { address: address}, function(results,
status) {
if (status == google.maps.GeocoderStatus.OK &&
results.length) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
latlng = results[0].geometry.location;
//here I wish to update the latlng variable
}
} else {
alert("Geocode was unsuccessful due to: " + status);
}
});
}
//end example
the var latlng it will not be setted since the call to the server and
so I can't visualize the map correctly. I know that I can inizialize,
in this example, the Map object inside the callback function of the
geocode method and the problem is solved, but in my application I need
to update a global variable inside the callback function, like the
"latlng" variable in the example.
Anybody knows some trick to do it???
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---