문제

나는 두 개의 지오 포인트 사이의 거리와 베어링을 계산하려고 노력하고 있습니다.이것은 인터넷에서 발견 한 코드이지만 다른 값을 반환합니다.

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));
.

logcat :

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top