這是prob。非常簡單,但我無法得到它。我有一個href鏈接,例如<a href="includes/driving.php?lat=38.254181&long=20.649962" class="driving" >Driving instructions</a>
點擊它(使用jQuery)時打開這樣的GoogleMap的:Google Maps JavaScript API v3向地圖發送動態變量
jQuery('a.driving').live('click',function(){
jQuery('#content').empty().load(jQuery(this).attr('href'), function(){
initGeolocation();
})
return false;
});
功能initGeolocation();
抓住HTML5的位置和有在頁面上超過1個class="driving"
鏈接。我無法實現的是將經緯度和長變量傳遞給地圖。我需要讓他們進入這個功能:
function calcRoute(position) {
var start = '38.313393,20.562651';
var end = 'lat' , 'long'
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
如果需要的地圖被稱爲像這樣(標準碼)
function success(position) {
var myOptions = {
zoom: 13,
center: new google.maps.LatLng(38.313393, 20.562651),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay = new google.maps.DirectionsRenderer({
'map': map,
'preserveViewport': true,
'draggable': true
});
directionsDisplay.setPanel(document.getElementById("directions_panel"));
google.maps.event.addListener(directionsDisplay, 'directions_changed',
function() {
if (currentDirections) {
oldDirections.push(currentDirections);
setUndoDisabled(false);
}
currentDirections = directionsDisplay.getDirections();
});
setUndoDisabled(true);
calcRoute(position);
}
幫助表示讚賞感謝
問題是我找不到它在谷歌文檔 –
PLZ訪問這裏https://developers.google.com/maps/documentation/javascript/directions#DirectionsRequests – Neji
嗨Nejil謝謝你,只是我不想要使用選擇框,假設我可以將變量添加到隱藏的輸入並按ID呼叫,但寧願使用get –