find Distance in kilometers in Android using google places Api

前端 未结 1 938
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 08:36

I want display the two places distance in kilometers for that I write the following code:

hyd(17.38,78.48) eluru(16.7,81.1)
 private String getDistance(doubl         


        
相关标签:
1条回答
  • 2021-01-16 08:55

    Use this method

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

    example

     public static double CalculateDistance(double lat1, double lng1, double lat2, double lng2) {
     float[] result=new float[1];
     Location.distanceBetween (lat1,lng1,lat2, lng2,  result);
     return (double)result[0]/1000; // in km
    }
    
    0 讨论(0)
提交回复
热议问题