Reputation: 9300
I'm trying to do some experiment with an app. I want that, given my location and given a distance, I get a point in Google Map to which I could walk that distance.
That has some complications since getting a point X miles out from you is "easy" but it's unlikely you'll actually walk that amount of miles unless you can actually go in a straight line.
The approach I followed is using google.maps.places.PlacesService
and the function nearbySearch
given a radius
. Then I process the distance to each returned point and luckily I get one point I could walk that distance far.
However, I've been trying some edge cases, like picking a road near a desert and then it won't work cause "places" are points of interest and that may be only just a plain road with nothing else than boring bushes for a long, long way.
In my mind it just should follow that road for the given distance and then stop.
To be clear:
I want to know from my starting
point, which would be my ending
point if I were to walk 1 Km
Do you have any better approach to this kind of situations?
Upvotes: 0
Views: 913
Reputation: 4248
The google.maps.DirectionsService
class will calculate the route a traveller would take, given an origin
and a destination
. It accepts a google.maps.DirectionsRequest
object. The DirectionsRequest has an option called TravelMode
, which will accept any of four constants (BICYCLING, DRIVING, TRANSIT, WALKING) from the google.maps.TravelMode
class.
To find a point, say, 3 kilometers from your location, I would:
DirectionsService
, using your current location and a point approximately 3 kilometers away from you.overview_path
, continually adding the length of the current segment to your grand total.I made you a Plunk demonstrating how this could be done.
Upvotes: 2