安卓百度地图计算两点之间的距离--binbinYang

xiaoxiao2021-02-27  155

LatLng stare = new LatLng(result.getList().get(i).getLatitude(), result.getList().get(i).getLongitude()); LatLng end = new LatLng(mLat, mLont); double double_distance = getDistance(stare, end); public double getDistance(LatLng start, LatLng end) { double lon1 = (Math.PI / 180) * start.longitude; double lon2 = (Math.PI / 180) * end.longitude; double lat1 = (Math.PI / 180) * start.latitude; double lat2 = (Math.PI / 180) * end.latitude; // 地球半径 double R = 6371; // 两点间距离 km,如果想要米的话,结果*1000就可以了 double d = Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * R; return d; }

百度地图  计算两点距离

1.首先要知道 第一个点的 经纬度

2.其次要知道 另外一个点的 经纬度

3.调用API 计算

转载请注明原文地址: https://www.6miu.com/read-14119.html

最新回复(0)