Nee*_*raj -4 java android location google-maps geolocation
输入:
要求输出:
从我当前位置提供半径的纬度列表.
有人能给我实现它的方法吗?
我有以下代码来检查传递的位置是否在传递的半径范围内...我们如何优化更多?我不是每次都使用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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
606 次 |
最近记录: |