Android : location.distanceto가 올바르게 작동하지 않습니까?
문제
나는 그것을 사용하여 거리를 계산하는 문제가 있습니다 Location.distanceTo
방법.
private class MyLocationOverlay1 extends MyLocationOverlay {
@Override
public void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when)
super.drawMyLocation(canvas,mapView,lastFix,myLocation,when);
Location bLocation = new Location("reverseGeocoded");
bLocation.setLatitude(FindList.gpslat); // Value = 3.294391E7
bLocation.setLongitude(FindList.gpslong); // Value = -9.6564615E7
Location aLocation = new Location("reverseGeocoded");
aLocation.setLatitude(myLocation.getLatitudeE6()); // Value = 3.2946164E7
aLocation.setLongitude(myLocation.getLongitudeE6()); // Value = -9.6505141E7
aLocation.set(aLocation); // Don't think I need this
bLocation.set(bLocation); // Don't think I need this either
int distance = (int)aLocation.distanceTo(bLocation); // Value = 12637795 ???
String str = " (" + String.valueOf(distance) + " meters)";
}
}
누군가 내 거리 계산이 12,637,795 미터를 보여주는 이유를 내 말을 할 수 있습니까?
해결책
선을 수정해야합니다.
aLocation.setLatitude(myLocation.getLatitudeE6() / 1e6);
aLocation.setLongitude(myLocation.getLongitudeE6() / 1e6);
라인을 제거하십시오.
aLocation.set(aLocation);
bLocation.set(bLocation);
제휴하지 않습니다 StackOverflow