Advertisement
janosoto

improveDistanceMetric

Jul 1st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. public static GeoPoint improveDistanceMetric(double radius, GeoPoint location,
  2.                                     double degree, DistanceMetric distanceMetric){
  3.     double factor = 0.5;
  4.     double error = radius * 0.01;
  5.     //Constantes de oblación
  6.     double latOblacion = 110540;
  7.     double longOblacion = 111320;
  8.     GeoPoint frontierPoint = new GeoPoint();
  9.     double dLat, dLong, distance;
  10.     do{
  11.         dLat = radius * Math.sin(Math.toRadians(degree)) * factor;
  12.         dLong = radius * Math.cos(Math.toRadians(degree)) * factor;
  13.         frontierPoint.setLatitude(location.getLatitude() + dLat / latOblacion);
  14.         frontierPoint.setLongitude(location.getLongitude() + dLong / (longOblacion
  15.                                 * Math.cos(Math.toRadians(location.getLatitude()))));
  16.         distance = distanceMetric.calculateDistance(location, frontierPoint);
  17.         if(distance * 1000 < radius - error){
  18.             factor += 0.01;
  19.         }
  20.         else if(distance * 1000 > radius + error){
  21.             factor -= 0.01;
  22.         }
  23.     }while(!(distance * 1000 > radius - error && distance * 1000 < radius + error));
  24.     return frontierPoint;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement