1

I'm writing an iOS application and need to get the duration time for a specific route (latitude, longitude points), how can I do that?

Thanks

Nate
  • 7,606
  • 23
  • 72
  • 124

2 Answers2

2

There are various methods to calculate the distance between two points given by lat/lng. The simplest is to use the functions provided by the spherical namespace of Google Maps API v3:

computeDistanceBetween(from:LatLng, to:LatLng)

There is even a method to compute the length of a path:

computeLength(path:Array.<LatLng>|MVCArray.<LatLng>)

To use these methods you would need to initialize Maps as follows:

<script type="text/javascript"
        src="http://maps.googleapis.com/maps/api/jslibraries=geometry&sensor=false"> 
</script>

And if you know the distance and the velocity, you can compute the time.

Community
  • 1
  • 1
Jiri Kriz
  • 9,192
  • 3
  • 29
  • 36
  • Looks good, but is there a way to know the kind of street it is (highway, slow path ...) so I can compute a better approximation? How does google do to compute a route duration? Does it take in account the traffic? I would like to be as precise as possible... thanks – Nate Aug 01 '11 at 13:57
  • Forgot to ask even if the answer seems obvious: Does the distance computed takes in account the street curves? – Nate Aug 01 '11 at 14:04
  • The mentioned functions compute the distance between lat/lng points as you asked in your question. They obviously do not account for curves, etc. Also I am not aware how Google computes the traveling time on streets. – Jiri Kriz Aug 01 '11 at 14:10
  • There is a misunderstanding... I'm looking for duration of a specific route (for a car), I thought there would be a function to get the duration by sending the route to a webservice for example. – Nate Aug 01 '11 at 14:28
  • I spent some time to answer your question as you asked it. There was nothing there about a route of a car or similar. I am sorry that I did not answer your indented question. It would be helpful when you make your question more precise. – Jiri Kriz Aug 01 '11 at 15:16
0

I finally found this: http://code.google.com/apis/maps/documentation/distancematrix/

Thanks to Jiri for his help!

Nate
  • 7,606
  • 23
  • 72
  • 124