这是概率。很简单,但我无法理解。我有一个 href 链接,例如<a href="includes/driving.php?lat=38.254181&long=20.649962" class="driving" >Driving instructions</a>
,当单击(使用 jQuery)时会打开一个像这样的 googlemap:
jQuery('a.driving').live('click',function(){
jQuery('#content').empty().load(jQuery(this).attr('href'), function(){
initGeolocation();
})
return false;
});
函数initGeolocation();
抓取 HTML5 位置,页面上有超过 1 个class="driving"
链接。我无法将 lat 和 long 变量传递给地图。我需要让他们进入这个功能:
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);
}
帮助感谢感谢