我在javascript函数中有问题,有两个变量在函数的全局范围内声明并在jquery插件中设置。如何在 jquery 之外获取这些变量值。
function GetDirectionFromCurrentLocation(StoreAddress) {
var positionStore = null;
var positionCurrent = null;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': StoreAddress }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
positionStore = results[0].geometry.location;
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
positionCurrent = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
});
}
});
window.open("http://maps.google.com/maps?saddr=" + positionCurrent + "&daddr=" + positionStore + "&hl=en&output=html");
}
这些变量始终为空。