-1

how can i get the distance between two points and show that distance in Google map? please help me. i have tried to get direction between two points but i am not able to get the distance between them.. my code is:

 private String getMapsApiDirectionsUrl() {

    String origin = "origin=" + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude();
    String destination = "destination=" + mDestLocation.latitude + "," + mDestLocation.longitude;
    /*String origin = mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude();
    String destination =mDestLocation.latitude + "," + mDestLocation.longitude;*/


    String waypoints = "waypoints=optimize:true|"
            + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude()
            + "|" + "|" + mDestLocation.latitude + ","
            + mDestLocation.longitude;
    String sensor = "sensor=false";
    String params = origin + "&" + destination + "&" + waypoints + "&" + sensor;
    String output = "json";
    String url = "https://maps.googleapis.com/maps/api/directions/"
            + output + "?" + params;

    return url;
 }
Phoenix
  • 238
  • 2
  • 12
Aks
  • 11
  • 7

2 Answers2

0

Please use - yourLocation.distanceTo(otherLocation);

where float distanceTo (Location dest) Returns the approximate distance in meters between this location and the given location. Distance is defined using the WGS84 ellipsoid.

Parameters dest Location: the destination location;

Vikram
  • 768
  • 2
  • 9
  • 23
0

Solution for this is in the following link : Find distance between two points on map using Google Map API V2
Hope this will works for you.

Community
  • 1
  • 1
Phoenix
  • 238
  • 2
  • 12