I provided a link to a working demo in my article, you can find it here: https://christianvarga.com/driving_distance.html. You need to look at that, then look at your own code to figure out where you went wrong. I can’t help you any further because you haven’t provided any code or explained your issue. I’m not a mind reader; saying “it doesn’t work” doesn’t give me any information that I can use to help you. Please read the following article: http://mattgemmell.com/what-have-you-tried/
]]>i have the same problem all i can see is the html session but the java wouldn’t work. Need some help please.
]]>Waypoints in directions
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
//var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var lanka = new google.maps.LatLng(7.8772157,80.7003428);
var mapOptions = {
zoom: 7,
center: lanka,
mapTypeId: google.maps.MapTypeId.HYBRID,
scrollwheel: false,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: false,
}
map = new google.maps.Map(document.getElementById(‘map-canvas’), mapOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
//alert(“test”);
var start = document.getElementById(‘start’).value;
var end = document.getElementById(‘end’).value;
//alert(start);
var waypts = [];
// var checkboxArray = document.getElementsByName(‘city’);//(‘waypoints’);
var checkboxArray = new Array();//new Array();
//alert(checkboxArray);
$(“.waypoints:checked”).each(function(index, element) {
checkboxArray[index] = $(this).val();
});
//alert(checkboxArray.length);
//alert(checkboxArray[1]);
for (var i = 0; i < checkboxArray.length; i++) {
waypts.push({
location:checkboxArray[i],
stopover:true});
}
//alert("sdgrs");
//var checkboxArray = document.getElementsByClassName('waypoints');
//var checkboxArray = document.getElementsByClassName('waypoints');
//alert(checkboxArray.length);
/*for (var i = 0; i < checkboxArray.length; i++) {
if (checkboxArray.options[i].checked == true) {
waypts.push({
location:checkboxArray[i].value,
stopover:true});
}
}*/
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById('directions_panel');
summaryPanel.innerHTML = '';
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
summaryPanel.innerHTML += 'Route Segment: ‘ + routeSegment + ‘‘;
summaryPanel.innerHTML += route.legs[i].start_address + ‘ to ‘;
summaryPanel.innerHTML += route.legs[i].end_address + ”;
summaryPanel.innerHTML += route.legs[i].distance.text + ”;
}
}
});
}
google.maps.event.addDomListener(window, ‘load’, initialize);
Start:
Colombo<!–
Boston, MA
New York, NY
Miami, FL–>
Waypoints:
(Check for multiple selection)
<!–
Kaluthata
Negombo
Ratnapura
Galle
Matara
Batticaloa
Trincomalee
Kandy
–>
<!–
Colombo–>
Kaluthata
Negombo
Ratnapura
Galle
Matara
Batticaloa
Trincomalee
Kandy<!–
Anuradhapura–>
End:
Anuradhapura<!–
Seattle, WA
San Francisco, CA
Los Angeles, CA–>
]]>You can do that using Waypoints: https://developers.google.com/maps/documentation/javascript/examples/directions-waypoints
]]>Thanks again for your valuable suggestion. I already tried some codes which provide me AIR distance between two points, not travled route distance. & Google Way-points had request/query limitation. grrrrr…..
]]>Are the vehicles tracked via GPS? This would allow you to get a very accurate measure of the distance travelled without relying on Google Maps. You could store the latlng every 10 seconds (or so), then at the end of the day, add up the distance between all the latlng points (which can be done mathematically: http://www.movable-type.co.uk/scripts/latlong.html). This would be very accurate. You could even look at how Uber tracks vehicles as an example. If you use Google Maps, the results will be wildly inaccurate – what if someone takes a different route, or doesn’t track one of the trips? There are many issues with this approach, if the data needs to be reliable then I wouldn’t recommend the use of Google Maps. Unfortunately I can’t help you build a solution, I think it would be better if you found a developer in Bangladesh who can come on site and build the solution with you in person.
]]>Thanks for your suggestion. I want to take some of your busy time. Plz read….
My company has a customized VTS (Vehicle Tracking Service) solution, which we assembled here in Bangladesh. I am the web application developer and front-end developed using HTML, CSS, JS, PHP, MySql. Recently one of our client requested us for some requirement. They need total distance covered by every vehicle day-wise. So that, after every 30days, they can calculate the total distance and can change engine oil on that notification. Thats why I need this on php to save in the database. Will you plz guide me or code for me ? My company will pay you for this. If yes, plz response. I will discuss some issues later. Thanks.