Android GPS坐标距离计算
Android API :
Android API--Location
http://androiddoc.qiniudn.com/reference/android/location/Location.htm
public float distanceTo (Location dest)
Added in API level 1
Returns the approximate distance in meters between this location and
the given location. Distance is defined using the WGS84 ellipsoid.Parameters dest the destination location Returns • the approximate
distance in meters
Location
Location API 接口
http://androiddoc.qiniudn.com/reference/android/location/Location.html
百度地图API:
static double getDistance(LatLng p1LL, LatLng p2LL)
返回两个点之间的距离
示例代码:
两种计算方式精确度对比:
LatLng latLng1 = new LatLng(37.014232, 117.565597);
LatLng latLng2 = new LatLng(31.137012, 121.345326);
double mDistance = DistanceUtil.getDistance(latLng1, latLng2);
Log.e(TAG, "onCreate: 百度-距离:" + mDistance + "米");
Location location1 = new Location("l1");
location1.setLatitude(37.014232);
location1.setLongitude(117.565597);
Location location2 = new Location("l2");
location2.setLatitude(31.137012);
location2.setLongitude(121.345326);
07-08 10:17:47.678 27561-27561/baidumapsdk.demo E/MainActivity:
onCreate: 百度-距离:740275.3203764297米 07-08 10:17:47.678
27561-27561/baidumapsdk.demo E/MainActivity:
onCreate: 谷歌-距离:740275.3203764297米