2

I am developing an Android app and want to get the road distance between 2 locations. If I understand correctly, the options are:

  1. Using the distanceTo() or distanceBetween() methods of the Location class — but this only provides the direct line instance.
  2. Using the Google Directions API — but this only seems to be available to Javascript, and I am developing in Java.

Are there any other options available? If so, an example would be appreciated.

Jon Adams
  • 22,969
  • 17
  • 78
  • 115
user396707
  • 397
  • 1
  • 3
  • 14

1 Answers1

3

You can get that response in JSON or XML from Maps API Web Services: http://code.google.com/intl/lv/apis/maps/documentation/directions/

The response will contain Legs (further divided in Steps) of calculated route and each leg will contain a distance field with value in meters. If there are multiple legs, You will need to add them together. If you do not have waypoints, there will be only one Leg.

Papuass
  • 327
  • 1
  • 10
  • Thanks very much for thr reply, but from the url – user396707 Feb 01 '11 at 16:05
  • Thanks very much for the reply, but from the url provided it says "Use of the Google Directions API is subject to a query limit of 2,500 directions requests per day". I presume that this is per app and not per handset, and so it very restrictive. Also the Premium Service allowing 100,000 request is a bit expensive.
    Any other info or ideas would be most appreciated
    – user396707 Feb 01 '11 at 16:14
  • Thanks very much for the reply, but from the url provided it says "Use of the Google Directions API is subject to a query limit of 2,500 directions requests per day". I presume that this is per app and not per handset, and so it very restrictive. Also the Premium Service allowing 100,000 request is a bit expensive.
    Any other info or ideas would be most appreciated
    – user396707 Feb 01 '11 at 16:14
  • Apologies - had a bit of trouble submitting – user396707 Feb 01 '11 at 16:36
  • What about Bing Maps? http://msdn.microsoft.com/en-us/library/ff701717.aspx Also, I am not sure on what is the limit, as Google Directions API does not requires a Maps API key, meaning it is not tied to the app, but rather device. – Papuass Feb 02 '11 at 10:55
  • Hi Papuass, Sorry for the delay in responding. If as you suggest, the Google Directions API limit (2,500 directions requests per day), applies to the device as opposed to the app, then you suggestion of using the Google Directions API is ideal. I will see if I can confirm this. Cheers – user396707 Mar 11 '11 at 13:39