以下变量 my_cords 在进入谷歌地图功能时未定义,任何人都可以理解为什么并可能给我一个解决方法吗?我已经在顶部定义了它并将它设置在一个回调函数中,我之前已经看到它在全局变量上工作..
$(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();
});