0

I wanted to make an android app which provides the distance between two areas in a city.

The user will have two input fields where he must enter the two area names he would like to find the distance.

After he enters the area name. My app should display the distance.

How should I implement this?

Pankaj Rathi
  • 65
  • 1
  • 11

3 Answers3

1

First of all you need to find latitude and longitude of that area name.

Convert both address in Location object, refer this.

Calculate distance by using distanceTo()

location1.distanceTo(location2);

Returns the approximate distance in meters between this location and the given location.

refer this for distanceTo() detail.

Community
  • 1
  • 1
Ravi
  • 34,851
  • 21
  • 122
  • 183
0

First get latitude and longitude of your start point and end point and using distanceBetween method of Location class calculate the distance here is link http://developer.android.com/reference/android/location/Location.html#distanceBetween(double,%20double,%20double,%20double,%20float[])

Ajinkya
  • 1,057
  • 7
  • 18
0

Use the Google Maps Directions API. You'll need to request the directions over HTTP. You can do this directly from Android, or via your own server.

For example, directions from Montreal to Toronto:

GET http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false

You'll end up with some JSON. In routes[].legs[].distance, you'll get an object like this:

  "legs" : [
        {
           "distance" : {
              "text" : "542 km",
              "value" : 542389
           },

You can also get the polyline information directly from the response object.

for more detail visit here. Get the distance between two locations in android?

Community
  • 1
  • 1
Harshad
  • 1,344
  • 1
  • 10
  • 25
  • Do you know how to implement it.. Because I have tried a lot using Google Maps Directions API but was unable to do that. Send me a sample program if you have. – Pankaj Rathi Mar 04 '16 at 18:19