我找到了很多解决方案来计算两个位置之间的距离,就像 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