我试图找到两点之间的中点时遇到了一些问题。这是我得到两点之间最短距离的部分:
double distance = 0;
double minDistance = Double.MAX_VALUE;
convertedHotSpotGeomList = RetrieveHotSpotAsyncTask.convertedHotSpotGeom;
LatLng[] minPoints = new LatLng[2];
for(int i = 0; i < convertedHotSpotGeomList.size(); i++){
LatLng point1 = new LatLng(convertedHotSpotGeomList.get(i).getY(), convertedHotSpotGeomList.get(i).getX());
LatLng point2 = new LatLng(convertedHotSpotGeomList.get(++i).getY(), convertedHotSpotGeomList.get(++i).getX());
distance = calculateDistance(point1, point2);
if(distance < minDistance){
minDistance = distance;
minPoints[0] = point1;
minPoints[1] = point2;
}
}
// Finish all the comparison and draw the circles
if(minPoints[0]!=null && minPoints[1] !=null){
CircleOptions circleOptions = new CircleOptions()
.center(minPoints[0])
.radius(1000)
.fillColor(Color.argb(95, 178, 30, 37))
.strokeColor(Color.TRANSPARENT);
CircleOptions circleOptions1= new CircleOptions()
.center(minPoints[1])
.radius(1000)
.fillColor(Color.argb(95, 88, 130, 37))
.strokeColor(Color.TRANSPARENT);
googleBasemap.addCircle(circleOptions);
googleBasemap.addCircle(circleOptions1);
midPoint(minPoints[0].latitude,minPoints[0].longitude,minPoints[1].latitude,minPoints[1].longitude);
}
}
然后从我绘制的两个圆圈的中心点开始,我称这种方法为中点:
private void midPoint(double lat1,double lon1,double lat2,double lon2){
double dLon = Math.toRadians(lon2 - lon1);
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
lon1 = Math.toRadians(lon1);
double Bx = Math.cos(lat2) * Math.cos(dLon);
double By = Math.cos(lat2) * Math.sin(dLon);
double lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
Log.i("LAT", String.valueOf(lat3));
Log.i("LON", String.valueOf(lon3));
CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(lon3, lat3))
.radius(1000)
.fillColor(Color.argb(95, 178, 30, 137))
.strokeColor(Color.TRANSPARENT);
googleBasemap.addCircle(circleOptions);
}
在中点,我想在谷歌地图上绘制另一个圆圈。但是,当我打印出中间点的lat和lng时,我得到了这个:
LAT 0.02512664 LON 1.811859
据我所知,谷歌地图的坐标应该是103.,1。我想这是因为格式不同,这就是为什么第三个圆圈没有出来的原因。有什么想法吗?
提前致谢。
答案 0 :(得分:0)
double lat3 = Math.atan2(Math.sin(lat1) +...
double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
这会返回弧度。转到学位:
double latdeg = Math.toDegrees(lat3);
double londeg = Math.toDegrees(lon3);
103.81187377279383
1.4396504253445948