I have a web application where i have one route which has a list of stops with latitude and longitude information , i want to plot this route on google map with all stops being displayed using some icon or a circle. I have gone through documentation but did not find any concrete example.Should i use polylines for such a use case
Asked
Active
Viewed 191 times
0
-
How many stops? Do you have the route polylines as well as the stops? Have you seen [the documentation on the directions service](https://developers.google.com/maps/documentation/javascript/directions)? – geocodezip Apr 13 '15 at 15:34
-
if you want to have a real route overlaying the streets, polylines will not be the thing you want, as they will directly connect the stops. – Flo Win Apr 13 '15 at 15:35
1 Answers
1
Here is a similar questions with no stops in between. You can adapt the example adding a waypoints object to your request.
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng(28.694004, 77.110291)
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
displayRoute();
}
google.maps.event.addDomListener(window, 'load', initialize);
function displayRoute() {
var start = new google.maps.LatLng(28.694004, 77.110291);
var end = new google.maps.LatLng(28.72082, 77.107241);
var directionsDisplay = new google.maps.DirectionsRenderer(); // also, constructor can get "DirectionsRendererOptions" object
directionsDisplay.setMap(map); // map should be already initialized.
var request = {
origin: start,
destination: end,
waypoints: [{
location: new google.maps.LatLng(28.64, 77.1),
stopover: true
}, {
location: new google.maps.LatLng(28.66, 77.41),
stopover: true
}],
travelMode: google.maps.TravelMode.DRIVING
};
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Waypoints in directions</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
</head>
<body>
<div id="map-canvas" style="float:left;width:400px;height:400px;"></div>
</body>
</html>