我正在使用谷歌地圖,我試圖訪問一個函數內的變量,但我不知道如何。在點擊事件中獲取變量Jquery
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);
});
}
我要訪問此
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);
}
});
initalLocation螢火告訴我initalLocation是不確定的。 任何想法?
乾杯
回調爲DirectionsService請求你注意到錯字初始化* I *分配?這不是在你的代碼雖然.. – Tamas 2013-03-13 13:39:43