I have defined variables named "delka" and "sirka", and I want to change their values in function below. Apparently, Im doing something wrong, because when the function ends, those variables arent affected by it. Why? Thx for answers.
var sirka;
var delka;
var mestoNaLL = document.getElementById("mesto").value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { "address": mestoNaLL }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
sirka = results[0].geometry.location.lat();
delka = results[0].geometry.location.lng();
} else {
alert("Chyba: " + status);
}
});
//undefined, why?
alert(mestoNaLL + " " + sirka + " " + delka + " ");
EDIT
here is the same problem, right?
//works fine
alert(markers[index].title + " " + infoWindows[index].content);
markers[index].addListener("click", function() {
//error - undefined
alert(markers[index].title + " " + infoWindows[index].content);
infoWindows[index].open(map, markers[index]);
map.setZoom(14);
map.setCenter(markers[index].getPosition());
});