【发布时间】:2014-06-30 06:06:13
【问题描述】:
输入:
- 当前位置经纬度
- 半径
- 经纬度附近列表
所需输出:
从我当前位置到提供的半径范围内的纬度列表。
谁能给我实现的方法?
我有以下代码来检查传递的位置是否在传递的半径范围内......我们如何优化更多? 我不是每次都使用 for 循环来检查我的所有位置
public static boolean pointIsInCircle(PointF pointForCheck, PointF center,
double radius) {
if (getDistanceBetweenTwoPoints(pointForCheck, center) <= radius)
return true;
else
return false;
}
public static double getDistanceBetweenTwoPoints(PointF p1, PointF p2) {
double R = 6371000; // m
double dLat = Math.toRadians(p2.x - p1.x);
double dLon = Math.toRadians(p2.y - p1.y);
double lat1 = Math.toRadians(p1.x);
double lat2 = Math.toRadians(p2.x);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2)
* Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = R * c;
return d;
}
【问题讨论】:
-
到目前为止,您在编码或搜索方面的努力在哪里?
-
@Smutje 我也提交了代码。您能否给出一些解决方案并删除您的反对票。
标签: java android google-maps geolocation location