我正在使用谷歌地图,我正在尝试访问函数内的变量,但我不知道如何。
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
// map.setCenter(initialLocation);
markerL = new google.maps.Marker({
position: initialLocation,
map: map,
title: "You are Here",
});
markerL.setMap(map);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
我想在这里访问 initalLocation
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('panel'));
var request = {
origin: window.initialLocation,
destination: 'london',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
Firebug 告诉我 initalLocation 未定义。有任何想法吗?
干杯