2

I'm a self-made developper and i have no idea of how to do this. I'm trying to set a program with android where the user will type in Textviews: the departure city, the arrival city, the date of departure and the time of departure. Then the app will show up the distance between the both cities, the duration of the trip, the arrival date and the arrival time.

I found some tools while searching but i dunno how to use them. Can anyone help me please. I've been stucked for weeks :-( ?

2 Answers2

5

You should use Google map distance matrix Api and Direction Api. First you sign up and get a token. Then you should call a web Api and the result would be a JSON which contains all information you want. just follow the link.

For the arrival time just add the trip duration with current time.

Sample WebApi :

https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=YOUR_API_KEY

Sample Response:

{
"destination_addresses" : [ "New York, NY, USA" ],
"origin_addresses" : [ "Washington, DC, USA" ],
"rows" : [
  {
     "elements" : [
        {
           "distance" : {
              "text" : "225 mi",
              "value" : 361715
           },
           "duration" : {
              "text" : "3 hours 49 mins",
              "value" : 13725
           },
           "status" : "OK"
        }
     ]
  }
],
"status" : "OK"
}
Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50
0

You can use any Distance Matrix API for these. For example, Distancematrix.ai. It has a free pricing plan, so may fit your needs better.

To start using the API, fill in a form here https://distancematrix.ai/contact, and you will instantly get a letter to your email with your token and detailed information on how to use it. During a 7-days trial period, you have the full unlimited access to Distance Matrix API and the opportunity to test it. When the trial period expires, you can continue using it for free, or you can switch to another pricing plan.

Besides, if you were using Google's API before the migration for you will be easy, because you don't need to rewrite code. You can compare the requests here:

Google:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=<origin_location_1|origin_location_2|...|origin_location_n>&destinations=<destination_location_1|destination_location_2|...|destination_location_n>&key=<your_access_token>

Distancematrix.ai:

https://api.distancematrix.ai/maps/api/distancematrix/json?origins=<origin_location_1|origin_location_2|...|origin_location_n>&destinations=<destination_location_1|destination_location_2|...|destination_location_n>&key=<your_access_token>

If you need a customizable solution or have some questions before you start, just feel free to respond to the letter you will get after filling out the form.

Disclaimer: I work at a company that creates this API.