2

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 .!!..

Mehul Solanki
  • 465
  • 7
  • 27
  • Use significant change updates instead of region monitoring – Wain Apr 15 '15 at 15:21
  • @Wain : Thanks for reply. Actually previously i was using Significant location update for this but i never gonna exact accurate like Region Monitoring. Even Previously i asked that issue. You can find my questions for that : 1. http://stackoverflow.com/questions/29248637/how-to-get-accurate-location-update-when-application-is-killed 2. http://stackoverflow.com/questions/29250289/not-able-to-get-notification-on-particular-location-like-reminder-application But this didn't help me and RegionMonitoring solved my problem with remain 20+ Region Monitoring issue. – Mehul Solanki Apr 16 '15 at 07:23

1 Answers1

5
  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.

Rendy Del Rosario
  • 1,277
  • 10
  • 20
  • I have implemented same logic..Works fine...but didExitRegion method call multiple times when device move from 3G network to WIfi...Could you please assist here? – Saumil Shah Sep 26 '15 at 06:27
  • didExitRegion does get called multiple times use region identifier to identify the region and ignore if you have already taken action – amar Nov 20 '17 at 06:29