두 점 사이의 중간 점을 찾으려고 할 때 몇 가지 문제가있었습니다.두 좌표에서 중간 점 계산
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);
}
을 여기에 내가 두 점 사이의 최단 거리를 얻는 부분은
중간 지점에서 Google지도에 다른 원을 그려야했습니다. 나는 중간 지점의 위도와 LNG를 인쇄 할 때 그러나, 나는이 무엇입니까 : 나는 알고 있었다 무엇인지는, 1. (103)에 있어야 구글지도 좌표
LAT 0.02512664 LON 1.811859
에서. 형식이 다르기 때문에 그것이 세 번째 원이 나오지 않는 이유입니다. 어떤 아이디어?
미리 감사드립니다.
우선 두 지점 간 최단 거리는 조금 이상합니다. 내가 아는 한, 포인트 사이에 거리는 하나뿐입니다. 두 좌표의 중앙값은 M ((lat1 + lat2)/2, (lng1 + lng2)/2) –
Opps는 불쌍한 설명을 유감스럽게 생각합니다. :) –