public double getDistance(double startLat,double startLong,double endLat,double endLong){ //startLong 起始坐标点经度 //startLat 起始坐标点维度 //endLong 目标坐标点经度 //endLat 目标坐标点维度 double lat1 = (Math.PI/180)*startLat; double lat2 = (Math.PI/180)*endLat; double lon1 = (Math.PI/180)*startLong; double lon2 = (Math.PI/180)*endLong; //地球半径 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; //double s=R*Math.acos(Math.cos(lat1*Math.PI/180 ) * Math.cos(lat2*Math.PI/180) * Math.cos(lng1*Math.PI/180 -lng2*Math.PI/180) + Math.sin(lat1*Math.PI/180 ) * Math.sin(lat2*Math.PI/180)); return d*1000;}
时间: 2024-11-03 20:56:12