简体   繁体   English

需要获得20多个区域监视通知

[英]Need to get more than 20 notification for Region Monitoring

I'm developing an application where user can set multiple locations. 我正在开发一个应用程序,用户可以在其中设置多个位置。 I get succeed to show notifications when user get Enter or Leave specific location boundary. 当用户获得Enter或离开特定位置边界时,我成功显示通知。

Now, there is situation that i need to provide monitoring for all saved locations and it can be hundreds and more. 现在,有些情况下我需要为所有保存的位置提供监视,并且可能有数百个甚至更多。 I've read in Apple Forum and many where that iOS devices allow only 20 Region Monitoring. 我在Apple论坛上读过很多文章,其中许多iOS设备仅允许20个区域监视。

在此处输入图片说明

I've develop my code to exceed this situation. 我已经开发了我的代码以超出这种情况。 I've set locationManager.distanceFilter = 200; 我已经设置locationManager.distanceFilter = 200; and when i get update for location. 当我获得位置更新时。 Firstly, i've stop all Region Monitoring and by conditions for nearest locations and again start Region Monitoring for 20 saved locations. 首先,我已停止所有区域监视,并按条件对最近位置进行了停止,然后再次为20个已保存位置启动了区域监视。

I think above solution may cause for missing any saved location while stopping and again re-starting Region Monitoring. 我认为上述解决方案可能会导致在停止并再次重新启动区域监视时丢失任何已保存的位置。 So, please provide me any other better solution to solve this only 20 notifications for Region Monitoring problem. 因此,请提供给我其他更好的解决方案,以解决区域监控问题的仅20条通知。

Have a nice day .!!.. 祝你今天愉快 。!!..

  1. Have an NSMutableArray with all the regions you want to monitor +20. 有一个NSMutableArray,其中包含您要监视的所有区域+20。
  2. Listen to significant location updates. 收听重要的位置更新。
  3. When you get a location update, if the NSMutableArray of all your regions is more than 20 then stop monitoring all regions been monitored and calculate the 20 nearest regions using the harvesine formula: 进行位置更新时,如果所有区域的NSMutableArray大于20,则停止监视所有被监视的区域,并使用harvesine公式计算20个最近的区域:

Harvesine - Objective C harvesine-目标C

Harvensine - Swift Harvensine-迅捷

That will give you the distance between the two locations. 这将为您提供两个位置之间的距离。 After that you could compare that distance with the region radius to know if is inside the region. 之后,您可以将该距离与区域半径进行比较,以了解是否在区域内。

Note: This distance will be in kilometers if your radius is on meters then just multiply the haversine method result with 1000 so that it's converted to meters. 注意:如果您的半径是以米为单位,则此距离将以公里为单位,然后将Haversine方法结果乘以1000,以便将其转换为米。

  1. Start monitoring the result list of the 20 nearest regions. 开始监视最近的20个区域的结果列表。

This will allow you to always monitor the 20 nearest regions based on your location. 这将使您始终可以根据自己的位置监视20个最近的区域。 Been able to monitor more than 20 since it will change the monitoring regions always to the 20 nearest regions. 能够监视20多个区域,因为它将始终将监视区域更改为20个最近的区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM