Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google map static drawing "route" instead of straight line

I succeeded in getting a google static map displaying a path between 2 coordinates.

The problem is that the drawn path is just a straight line between the 2 points.

I read that to be able to draw the "route" between 2 points on a static google map, as in, following the roads and city geography instead of the straight line, I need to add all the coordinates/crossroads for the path.

Does anyone knows an easy solution to solve this?

like image 610
Pierre Avatar asked Oct 13 '10 08:10

Pierre


2 Answers

You can definitely do this with the Static Maps API:

get directions using DirectionsService:

https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsService

and convert the overview path to suit the requirements of the Static Maps API:

https://developers.google.com/maps/documentation/maps-static/start#Paths

like image 152
Chris Broadfoot Avatar answered Sep 18 '22 20:09

Chris Broadfoot


Using Polylines u can draw straight line.

The Polyline class defines a linear overlay of connected line segments on the map. A Polyline object consists of an array of LatLng locations, and creates a series of line segments that connect those locations in an ordered sequence.

u can see the example here

https://google-developers.appspot.com/maps/documentation/javascript/examples/polyline-simple

about polylines

https://developers.google.com/maps/documentation/javascript/overlays

like image 39
vinod_vh Avatar answered Sep 18 '22 20:09

vinod_vh