Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public LatLng midPoint(LatLng A, LatLng B) {
  2. double phi1 = Math.toRadians(A.latitude);
  3. double gamma1 = Math.toRadians(A.longitude);
  4.  
  5. double phi2 = Math.toRadians(B.latitude);
  6. double deltaGamma = Math.toRadians(B.longitude - A.longitude);
  7.  
  8. double aux1 = Math.cos(phi2) * Math.cos(deltaGamma);
  9. double aux2 = Math.cos(phi2) * Math.sin(deltaGamma);
  10.  
  11. double x = Math.sqrt((Math.cos(phi1) + aux1) * (Math.cos(phi1) + aux1) + aux2 * aux2);
  12. double y = Math.sin(phi1) + Math.sin(phi2);
  13. double phi3 = Math.atan2(y, x);
  14.  
  15. double gamma3 = gamma1 + Math.atan2(aux2, Math.cos(phi1) + aux1);
  16.  
  17. // normalise to −180..+180°
  18. return new LatLng(Math.toDegrees(phi3), (Math.toDegrees(gamma3) + 540) % 360 - 180);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement