Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public LatLng midPoint(LatLng A, LatLng B) {
- double phi1 = Math.toRadians(A.latitude);
- double gamma1 = Math.toRadians(A.longitude);
- double phi2 = Math.toRadians(B.latitude);
- double deltaGamma = Math.toRadians(B.longitude - A.longitude);
- double aux1 = Math.cos(phi2) * Math.cos(deltaGamma);
- double aux2 = Math.cos(phi2) * Math.sin(deltaGamma);
- double x = Math.sqrt((Math.cos(phi1) + aux1) * (Math.cos(phi1) + aux1) + aux2 * aux2);
- double y = Math.sin(phi1) + Math.sin(phi2);
- double phi3 = Math.atan2(y, x);
- double gamma3 = gamma1 + Math.atan2(aux2, Math.cos(phi1) + aux1);
- // normalise to −180..+180°
- return new LatLng(Math.toDegrees(phi3), (Math.toDegrees(gamma3) + 540) % 360 - 180);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement