Need to get more than 20 notification for Region Monitoring

前端 未结 1 1321
借酒劲吻你
借酒劲吻你 2021-01-03 14:53

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.

N

相关标签:
1条回答
  • 2021-01-03 15:32
    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.

    0 讨论(0)
提交回复
热议问题