新GPS坐标的最准确计算是什么?

时间:2016-10-14 10:33:30

标签: java android gps coordinates

爵士

我已经提到这个website从给定的旧起点(22.36818013084568,114.11599405109882),轴承(在Rad)1.1583078679283372和距离(以米为单位)计算新坐标:134.07025146484375 )。说到执行,它错误地给出了(0.3904068271541288,1.9917206728639663)。你能告诉我哪个部分我弄错了或者用于计算新职位的任何修改算法?

public static double getDistanceInMeters(LatLng sp1, LatLng sp2) {


    int lat = (int) (sp1.latitude * 1E6);
    int lng = (int) (sp1.longitude * 1E6);
    GeoPoint p1 = new GeoPoint(lat, lng);


    int latX = (int) (sp2.latitude * 1E6);
    int lngX = (int) (sp2.longitude * 1E6);
    GeoPoint p2 = new GeoPoint(latX, lngX);

    double lat1 = ((double)p1.getLatitudeE6()) / 1e6;
    double lng1 = ((double)p1.getLongitudeE6()) / 1e6;
    double lat2 = ((double)p2.getLatitudeE6()) / 1e6;
    double lng2 = ((double)p2.getLongitudeE6()) / 1e6;
    float [] dist = new float[1];
    Location.distanceBetween(lat1, lng1, lat2, lng2, dist);
    return dist[0]  ;
}

    double distance = SystemUtils.getDistanceInMeters(dronePosition, devicePos )- followDist;

public static LatLng fromBearingDistance(LatLng originalPosition, double brng, double d) {     

    double lat1 = Math.toRadians(originalPosition.latitude) ;
    double lon1 = Math.toRadians(originalPosition.longitude);

     long R = 6371000; // distance of earth's radius in meters
     d = d /(double) R;

    System.out.println("d/R :" + d/R ) ;
    System.out.println("    Math.cos(d/R) :" +  Math.cos(d/R)  ) ; 
    System.out.println("    Math.sin(d/R) :" +  Math.sin(d/R)  ) ;
    //(in km)
    double lat2 = Math.asin( Math.sin(lat1)*Math.cos( d ) +     Math.cos(lat1)*Math.sin( d )*Math.cos(brng) );

    double lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d )*Math.cos(lat1), 
                     Math.cos(d )-Math.sin(lat1)*Math.sin(lat2));


    return new LatLng(lat2,lon2);   
}

0 个答案:

没有答案