And I am using Qt, so the map is shown on the widget.
Global variables:
var arrayMarkers = new Array();
var arrayIndex = 0;
This function “gets” called and also “displays” markers on the map where I click. Also it duly calls the displayRoute function when I click the second time.
function Open (x, y)
{
google.maps.event.addListener (map, "click",
function (event)
{
alert("You clicked the map."+ event.latLng.toString(4));
arrayMarkers [arrayIndex] = event.latLng;
var point1 = new google.maps.Marker ({
position:arrayMarkers [arrayIndex],
draggable:false,
map:map,
flat:true
});
if (arrayIndex == 1)
{
displayRoute();
}
arrayIndex++;
});
}
The alert is shown properly when the following displayRoute function gets called. But that’s it, the route does NOT get displayed! The alert in the directionsService.route call is NOT shown, that means the function directionsService.route doesn’t get even called? What to do? Please help.
function displayRoute ()
{
alert ("displayRoute");
var start = arrayMarkers [0];
var end = arrayMarkers [1];
var request = {
origin:start,
destination:end,
travelMode:google.maps.TravelMode.DRIVING
};
directionsService.route (request,
function (result, status)
{
alert(status);
if (status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections (result);
pointsArray = result.routes[0].overview_path;
var j = 0;
for (j = 0; j < 49; j++)
{
var point1 = new google.maps.Marker ({
position:pointsArray[j],
draggable:true,
map:map,
flat:true
});
}
}
});
}
I had included some values in < script src > without knowing what they are
:banghead::banghead::banghead:
The original was:
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>I had modified it to:
Changing it back to normal displays the route!