0

我想开发一个基于位置的应用程序。

要求:用户插入数据(经纬度)并存储在 SQLite 中。当用户到达该位置时,他/她将收到警报。我想在这个位置附近定义一些区域(例如 1 公里)。如果用户在该位置的 1 公里范围内,则他/她会收到警报。

我知道如何使用位置监听器,但不知道修复这个圆圈区域。

我看了这个,但不知道如何使用它。

有人可以建议我吗?谢谢

4

2 回答 2

0

有什么难的?

要知道当前点是否在任何 1km 半径内?

如果到圆心的距离小于半径,则点在圆内!

所以只需使用 CLLocation 的 distanceTo 方法,并检查是否小于 1000。对所有点都这样做。

for (int i = 0; i < numpoints; i++) {
  dist = currentLocation.distanceTo(point[i].latitude, point[i].longitude);
  if (dist < 1000) {
     // found: signal point reached
  }
}

除非你有十万个点,否则这种方法有效,将所有点加载到主内存到一个大数组中。

于 2013-10-04T18:08:36.827 回答
0
No need to calculate distance , you can compare the longitude and latitudes within radius of 1km

        double lat1 = Double.parseDouble(lat);
        double lon1 = Double.parseDouble(lon);

        double incrlng = 0.85;
        double incrlat = (radius in km)/ (Math.cos(lat1/57.3)*69.1);
         //here below lat1 is your latitude and lon1 is your longitude               
         north = lat1 + incrlat;
         west = lon1 - incrlng;
         south = lat1 - incrlat;
         east  = lon1 + incrlng; 

check your latitude and longitude with the above co-ordinates,like below
if(latitude >= south && latitude  <= north && longitude <= east && longitude >= west)// check the user latitude and longitude satisfies the if condition, if so he is within the 1 KM radius. 
于 2018-03-29T09:35:03.830 回答