/[projects]/dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/GeoPoint.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/GeoPoint.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2578 by torben, Thu Jun 11 20:39:28 2015 UTC revision 2579 by torben, Thu Jun 11 21:10:17 2015 UTC
# Line 25  public class GeoPoint { Line 25  public class GeoPoint {
25                  return 62.8 * Math.sqrt( 3.1 * (pwrLat + pwrLng) );                              return 62.8 * Math.sqrt( 3.1 * (pwrLat + pwrLng) );            
26          }                }      
27    
28          public static float beregnAfstand(GeoPoint p1, GeoPoint p2) {  /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
29    /*::  This function converts decimal degrees to radians             :*/
30    /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
31    private static double deg2rad(double deg) {
32      return (deg * Math.PI / 180.0);
33    }
34    
35    /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
36    /*::  This function converts radians to decimal degrees             :*/
37    /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
38    private static double rad2deg(double rad) {
39      return (rad * 180 / Math.PI);
40    }
41    
42            //http://www.geodatasource.com/developers/java
43            private static double distanceHaversine(double lat1, double lon1, double lat2, double lon2) {
44      double theta = lon1 - lon2;
45      double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
46      dist = Math.acos(dist);
47      dist = rad2deg(dist);
48      dist = dist * 60 * 1.1515;
49      
50    //indtil nu er dist i miles - så vi omregner lige til km
51      dist = dist * 1.609344;
52      return (dist);
53    }
54    
55            public static double beregnAfstand(GeoPoint p1, GeoPoint p2) {
56                    return distanceHaversine(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
57            }
58    
59    
60            // denne er nok den mest præcise - men er også den langsomste
61            public static float beregnAfstand_google(GeoPoint p1, GeoPoint p2) {
62                  float[] result = new float[1];                  float[] result = new float[1];
63                                    
64                  computeDistanceAndBearing(p1.latitude, p1.longitude, p2.latitude, p2.longitude, result);                  computeDistanceAndBearing(p1.latitude, p1.longitude, p2.latitude, p2.longitude, result);

Legend:
Removed from v.2578  
changed lines
  Added in v.2579

  ViewVC Help
Powered by ViewVC 1.1.20