DistanceTo() 两地之间的距离不正确

DistanceTo() incorrect distance between two places

在我的应用程序中,我使用方法 "DistanceTo()" 来获取地点之间的距离,但无法正常工作!!这是我的这个距离的代码:

double  latitudine;
double longitudine;
latitudine = 40.17;
longitudine = 24.9;
Location qui = new Location("Corrente");
qui.setLatitude(latitudine);
qui.setLatitude(longitudine);

double  latitudine2;
double longitudine2;
latitudine2 = 40.16;
longitudine2 = 25;
Location due = new Location("Corrente2");
due.setLatitude(latitudine2);
due.setLatitude(longitudine2);
float b =  qui.distanceTo(due);
Toast.makeText(getBaseContext(), "DESTINAZIONE KILOMETRI b:" + b, Toast.LENGTH_SHORT).show();

吐司显示11077.14米,但距离应该是8.5公里!!如这些网站所示:http://www.movable-type.co.uk/scripts/latlong.html http://www.mapdevelopers.com/distance_from_to.php 在这种情况下,差异大约为 3 公里,但有时差异有时甚至更大!!请帮我!为什么这段代码不能正常工作?谢谢

可能想看看 Point2D.Distance。它returns

the distance between the two sets of specified coordinates.

您没有在 Locations 上同时调用 setLongitude,您需要:

qui.setLongitude(longitudine);
due.setLongitude(longitudine2);