Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Tracks - tracking route taken

We are developing an app for a client, one function of which is the following:

User selects "Start Journey" and then at predefined intervals gets current location (probably lat/long) from GPS. User selects "End Journey"

At the end of the journey, we would like to know the distance travelled. At no point is a display of a map necessary, simply the journey distance. We may not know the route in advance. Also, part of journey may be on public transport, rail etc. It is possible we could prompt user for "mode of transport change" en-route.

It seems to me that Google Maps Tracks could be an appropriate tool, but I cannot seem to see how I would do this.

We also have a need for predefined routes. Again, no map is strictly needed, we would be perfectly happy with a set of routes in text from from the Maps Directions api, but the terms of service seem to strictly prohibit directions in map-less form.

The distance travelled may be calculated server-side if the app presents a set of journey waypoints as a submission to our internal api, and in this case the google api's would be accessed by php.

Any bright ideas ? (Apologies if this is a duplicate of some other query, but I'm damned if I can find anything!)

like image 285
David Shields Avatar asked Oct 11 '25 13:10

David Shields


1 Answers

The question might be the duplicate to Google maps saving draggable directions, but it depends on how people see it.

Basically, you add an event to your directionsRenderer when it's changed.

google.maps.event.addListener({{directionsRenderer}},'directions_changed', function() {
  var waypoints = directionsRenderer.directions.route[0].legs[0].via_waypoint;
});

When user confirm the route, you save the origin, destination, travel mode, and waypoints, and check it with the existing ones.

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

You can also get a polyline from directions, then use it if you want.

like image 102
allenhwkim Avatar answered Oct 14 '25 04:10

allenhwkim