問題描述
double distance;
Location locationA = new Location("point A");
locationA.setLatitude(latA);
locationA.setLongitude(lngA);
Location locationB = new Location("point B");
locationB.setLatitude(latB);
LocationB.setLongitude(lngB);
distance = locationA.distanceTo(locationB);
上面的代碼不起作用,我的距離是 0.0 公里?同樣在位置類的構造函數(shù)中,字符串提供者是什么意思.在上面的代碼中,我使用 PointA 和 PointB 作為提供者.
the above code is not working and i am getting 0.0 Km as distance? Also in the constructor of the location class, what does the string provider mean. In the above code i am using PointA and PointB as the providers.
為什么上面的代碼不起作用?
why is the above code not working?
提前謝謝你.
LOGCAT05-09 17:48:56.144:信息/當前位置(1573):緯度 0.0 lng 0.005-09 17:48:56.155: 信息/檢查位置 loc(1573): lat 54.4288665 lng 10.169366
LOGCAT 05-09 17:48:56.144: INFO/current loc(1573): lat 0.0 lng 0.0 05-09 17:48:56.155: INFO/checklocation loc(1573): lat 54.4288665 lng 10.169366
推薦答案
試試Location.distanceBetween(..)
更新:
如果您從 GeoPoint 獲取緯度/經(jīng)度,那么它們是微度數(shù).您必須乘以 1e6.
If you are getting lat/lon from GeoPoint then they are in microdegrees. You must multiply by 1e6.
這篇關于如何找到兩個地理點之間的距離?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!