簡體   English   中英

android中兩個地理位置之間的距離和方位

[英]distance and bearing between two geopoints in android

我正在嘗試計算兩個地理位置之間的距離和方位。 這是我在互聯網上找到的代碼,但是它返回不同的值。

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

因此,任何人都可以幫助我使用這些方法,並告訴我哪種方法才是正確的方法。 謝謝

在您的代碼中:

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

您設置了兩次緯度。 更正后,它會給出絕對正確的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM