Hi. I have these two functions:
var geocoder = new google.maps.Geocoder();
var address = "";
$.getJSON("/Club/GetClubFullAddress/" + $("#ClubID").val().toString(),
function (data) {
address = data.Address;
alert(data.Address);
});
if (geocoder) {
geocoder.geocode({ 'address': address }, function (results, status) {
alert(address);
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
}
else {
alert("Geocoding failed: " + status);
}
});
}
When i set the address to a hardcoded address, the geocoder function works fine. however, when i retrieve the address with the json function, and set the address to the value returned (a string - which i use to test the geocode function by hardcoding the value), the geocoder function always fails. what am i missing? why is it able to read a string that i set manually but not the one returned by json? i set up the alerts, one before the geocode and one after, and the address IS ACTUALLY SET RIGHT. it's just not being picked up by the geocoder. please help
Edit:
I have even changed it to this:
$.getJSON("/Club/GetClubFullAddress/" + $("#ClubID").val().toString(),
function (data) {
getLatitude(encodeURI(data.Address));
});
function getLatitude(address) {
if (geocoder) {
geocoder.geocode({ 'address': address }, function (results, status) {
alert(address);
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
}
else {
alert("Geocoding failed: " + status);
}
});
}
}
and i'm still getting no results