【问题标题】:distance and bearing between two geopoints in androidandroid中两个地理点之间的距离和方位
【发布时间】:2014-04-13 22:00:07
【问题描述】:

我正在尝试计算两个地理点之间的距离和方位。这是我在互联网上找到的代码,但它返回的值不同。

double currentLat = 51.43376;
    double currentLng = -2.86221;

    double destLat = 51.43503; 
    double destLng = -2.86869;

    final float[] results= new float[3];
    Location.distanceBetween(currentLat, currentLng, destLat, destLng, results);
    System.out.println("GPS" + "results[0]: " + results[0]);
    System.out.println("GPS" + "results[1]: " + results[1]);
    System.out.println("GPS" + "results[2]: " + results[2]);


    Location here = new Location("Current");
    here.setLatitude(currentLat);
    here.setLatitude(currentLng);

    Location dest = new Location("Destination2");
    dest.setLatitude(destLat);
    dest.setLongitude(destLng);


    System.out.println("GPS" + "Bearing to dest: " + here.bearingTo(dest));
    System.out.println("GPS" + "Distance to dest: " + here.distanceTo(dest));

日志猫:

04-13 17:46:13.056: I/System.out(1349): GPSresults[0]: 472.2533
04-13 17:46:13.056: I/System.out(1349): GPSresults[1]: -72.5882
04-13 17:46:13.066: I/System.out(1349): GPSresults[2]: -72.59327
04-13 17:46:13.066: I/System.out(1349): GPSBearing to dest: -2.2131138
04-13 17:46:13.066: I/System.out(1349): GPSDistance to dest: 6023135.0

所以任何人都可以帮助我使用这些方法并告诉我哪个是正确的使用方法。 谢谢

【问题讨论】:

    标签: android geolocation distance geopoints bearing


    【解决方案1】:

    在您的代码中:

    Location here = new Location("Current");
    here.setLatitude(currentLat);
    here.setLatitude(currentLng);
    

    您设置了两次纬度。更正了,它给出了绝对正确的结果。

    【讨论】:

    • 哦,我真的为这个愚蠢的错误感到尴尬。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 2011-12-24
    相关资源
    最近更新 更多