The following variable my_cords is undefined when it gets to the google maps function, can anyone understand why and possible give me a work around? I have defined it right at the top and set it inside a callback function, which I have seen work on global variables before..
$(document).ready(function () {
var my_cords;
var map;
function getCareHome() {
geocoder = new google.maps.Geocoder();
//var address = document.getElementById("address").value;
var address = "address here";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
my_cords = results[0].geometry.location;
} else {
alert("Sorry we couldn't locate the carehome on the map: " + status);
return false;
}
});
var myOptions = {
zoom: 7,
center: my_cords,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
getCareHome();
});