Get the distance between two locations in android?

前端 未结 10 577
醉梦人生
醉梦人生 2020-11-28 07:57

i need to get distance between two location, but i need to get distance like blue line in the picture. \"picure\"

10条回答
  •  星月不相逢
    2020-11-28 08:34

    You can use following method of Location class in android (if u have lat, longs of both the locations) the method returns approximate distance in meters.

    public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)

    Explanation:

    Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them. Distance and bearing are defined using the WGS84 ellipsoid.

    The computed distance is stored in results[0]. If results has length 2 or greater, the initial bearing is stored in results[1]. If results has length 3 or greater, the final bearing is stored in results[2]. Parameters:

    startLatitude - the starting latitude

    startLongitude the starting longitude

    endLatitude the ending latitude

    endLongitude the ending longitude

    results an array of floats to hold the results

提交回复
热议问题