I want to draw a routes between every two points in map using Google map API.
Drawing routes between markers using Google map API
1.5k views Asked by Ghaly Saqqal At
3
There are 3 answers
5
On
var polylineOptions = {
strokeColor: routeColor,
strokeOpacity: 0.5,
strokeWeight: 8
};
var rendererOptions = {
draggable: false,
polylineOptions: polylineOptions,
suppressMarkers: true,
preserveViewport: true
};
routePoly = new google.maps.Polyline(polylineOptions);
routeRenderer = new google.maps.DirectionsRenderer(rendererOptions);
routePoly.setPath(new Array());
var polyPath = routePoly.getPath();
for (var i = 0; i< coordinates.length ; i++){
polyPath.push(coordinates.latLng);
}
routePoly.setMap(map);
___UPDATE___
You asked for the HTML. The thing is HTML is dynamic. I will post the initial version. I have bunch of other divs there but they are NOT important for your case. (I know this is bare bone of my HTML but it dynamically generated depending on user actions). Regardless, The only div that matters for your is map-canvas. Google Map requires this div to be present and draws MAP and other fancy stuff there.
<!doctype html>
<html lang="en">
<body>
<div id="wholeBody">
<div id="map-canvas">
</div>
</div>
</body>
</html>
1
On
If you just want to draw lines according to a set of points (coordinates) you can use the simple set polylines as in this example but if you want to get the road routes that connect the two points you have to delve into the service google maps directions Here a link introductory
this my full answer about all my questions in this question :