2
DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?"
DIRECTION_URL_API + "origin=" + origin + "&destination=" + destination  + "&sensor=true" + "&mode=" +typeOpt+"&key=" + GOOGLE_API_KEY  ;

I am using this format but its not working

Please suggest me :)

Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42
taru khan
  • 13
  • 6
  • 1
    Possible duplicate of [How to calculate distance between two locations using their longitude and latitude value](https://stackoverflow.com/questions/6981916/how-to-calculate-distance-between-two-locations-using-their-longitude-and-latitu) – Sathish Kumar J Nov 08 '17 at 03:44

2 Answers2

0

You can find distance following way http://maps.googleapis.com/maps/api/directions/json?origin=21.1702,72.8311&destination=21.7051,72.9959&sensor=false&units=metric&mode=driving

origin=lat1,long1 destination=lat2,long2

Rajesh N
  • 6,198
  • 2
  • 47
  • 58
0

Please use the below method to calculate the distance between two points

/**
 * Returns Distance in kilometers (km)
 */
public static String distance(double startLat, double startLong, double endLat, double endLong) {
    Location startPoint = new Location("locationA");
    startPoint.setLatitude(startLat);
    startPoint.setLongitude(startLong);

    Location endPoint = new Location("locationA");
    endPoint.setLatitude(endLat);
    endPoint.setLongitude(endLong);

    return String.format("%.2f", startPoint.distanceTo(endPoint) / 1000); //KMs
}

Method usage -

String mDistance  = distance(startLat,
                    startLong,
                    endLat,endLng)).concat("km");
Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42