This is prob. very simple but I can’t get it. I have a href link e.g. <a href="includes/driving.php?lat=38.254181&long=20.649962" class="driving" >Driving instructions</a> which when clicked (using jQuery) opens a googlemap like this:
jQuery('a.driving').live('click',function(){
jQuery('#content').empty().load(jQuery(this).attr('href'), function(){
initGeolocation();
})
return false;
});
Function initGeolocation(); grabs the HTML5 location and there are more than 1 class="driving" links on the page. What I cannot get to happen is passing the lat and long variables to the map. I need to get them into this function:
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);
}
});
}
if needed the map is called like this (standard code)
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);
}
Help appreciated thanks
Hi, well if you have your co-ordinates ready, then why don’t you create
google.maps.LatLngobject by this way:new google.maps.LatLng(your lat, your lon), if you want to specifystringthen do it this waynew google.maps.LatLng("address")and assign this latlng object to start and end. This will solve your problem. For more details please visitGoogle’s documentation.:)