我找到了很多解決方案來計算兩個位置之間的距離,就像 how to find the distance between two geopoints? 或 Calculating distance between two geographic locations 或更具體,這裏的.distanceTo方法的代碼:Android - 如何從我的數據庫中獲取位於我位置附近給定距離內的位置?
Location locationA = new Location("point A");
locationA.setLatitude(pointA.getLatitudeE6()/1E6);
locationA.setLongitude(pointA.getLongitudeE6()/1E6);
Location locationB = new Location("point B");
locationB.setLatitude(pointB.getLatitudeE6()/1E6);
locationB.setLongitude(pointB.getLongitudeE6()/1E6);
double distance = locationA.distanceTo(locationB);
如果我有一個位置(我們說「locationA」),我有一個帶有POI位置數據的數據庫,我只對那些位置感興趣,位於給定距離(比如說「距離」)內的位置「locationA」我如何獲得這些?
如果我寫的方法
private Location[] poiAroundMe (Location locationA, double distance) {
// The necessary calculation
return locationsAroundMeWithinTheGivenDistance[];
}
什麼是 「必要的計算」?
我很確定,沒有內置的方法,所以我想尋求幫助。
謝謝!
是的,這就是我想到的,而不是「距離圓」,我應該使用「距離平方」。不像我第一次想要的那樣準確,但是,嘿,它工作。 :-)經度 myLongitude - 距離和緯度 myLatitude - 距離; –
lpasztor