ioscllocationmanagerregion-monitoringclcircularregion

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.

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.

enter image description here

I've develop my code to exceed this situation. I've set 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.

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.

Have a nice day .!!..


Solution

    1. Have an NSMutableArray with all the regions you want to monitor +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:

    Harvesine - Objective C

    Harvensine - Swift

    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.

    1. Start monitoring the result list of the 20 nearest regions.

    This will allow you to always monitor the 20 nearest regions based on your location. Been able to monitor more than 20 since it will change the monitoring regions always to the 20 nearest regions.