转至 http://blog.youkuaiyun.com/chentravelling/article/details/51058742 /** * 计算两点之间距离 * @param start * @param end * @return 米 */ public String getDistance(LatLng start,LatLng end){ double lat1 = (Math.PI/180)*start.latitude; double lat2 = (Math.PI/180)*end.latitude; double lon1 = (Math.PI/180)*start.longitude; double lon2 = (Math.PI/180)*end.longitude; //地球半径 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; if(d<1) return (int)d*1000+"m"; else return String.format("%.2f",d)+"km"; }
百度地图计算两点之间的距离
最新推荐文章于 2024-10-25 15:13:48 发布
本文介绍了一种计算地球上两点间地理距离的方法,并提供了一个具体的Java实现示例。该方法使用经纬度坐标,通过数学公式计算两点间的直线距离,支持返回公里或米为单位的距离。
5553

被折叠的 条评论
为什么被折叠?



