iOS Geofence CLCircularRegion monitoring. locationManager:didExitRegion does not seem to work as expected

前端 未结 9 739
陌清茗
陌清茗 2020-11-28 03:09

I am currently trying to get my app to monitor particular regions using CoreLocation however I am finding that it does not seem to work as expected, it seems to

相关标签:
9条回答
  • 2020-11-28 03:53

    I like the answers by both Michael and Nevan. I would like to add more information from my personal experience/opinion in developing Location Based iOS Application with Region Monitoring and also highlight some important points:-

    Be realistic on Region Monitoring

    Region Monitoring is using Global Positioning System (GPS), Wifi and other technologies to determine if the device is inside or outside the monitored region. Don't forget that our earth is 510 square kilometers and about 30% are land (149 million km2). It is a huge area. Remember the recent MH370 missing case? Our current most advance technology could not even pinpoint an estimated region of that missing plane.

    If you want to monitor for a small region with only 10 meter radius. It could possibly work inside a highly dense city with a lot of cell towers and wifi connected areas. But at the same time, the signal might be blocked by high rise towers which might cause the signal loss for a few seconds/minutes which caused the delay in delivering the notification.

    So, you really have to consider the above information before deciding how big is the region that you want to monitor. Personally I think 10 meter radius is too small.

    Be Realistic on the Number of Monitored Regions

    The current Core Location technology can only monitors up to maximum 20 regions on a single app. Make sure that the monitored regions are not too close to each other as well.

    I personally have tested 3 regions that are about 100 meters in radius which are about 200 meters aways from each others. Sometimes I can get notifications from all these 3 regions when I am driving through them, but sometimes, I can only get the notification from the First region only. What could be the reason? I could not know. The regions might be too close to each other. Or the cell towers decide that my device does not actually inside the monitored region.

    There was one person on StackOverFlow who wants to monitor 1800 points on our Earth. Don't be like him as he is quite unrealistic and probably does not understand the limitation of current Core Location technology. Link: Check if the user location is near of some points

    Fine Tune The LocationManager

    If your app needs to monitor a small area or needs the location update frequently. Here are the potential properties of your location Manager.

    self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    self.locationManager.activityType = CLActivityTypeAutomotiveNavigation;
    

    kCLLocationAccuracyBestForNavigation will consume more battery compare with kCLLocationAccuracyBest. But, it will be more accurate.

    I found a glitch in region monitoring in iOS 7 when there are multiple notifications triggered at the same time in different monitored regions. I have found a solution to filter out this glitch. For more info, please visit: Region Monitoring Glitch on iOS 7 - Multiple Notifications at the same time

    Don't Be Over Ambitious

    You might have used some apps which can monitor a small region and are very accurate and able to notify your the same second you step into the region. And you have the inspiration to develop the exact same app to compete with them. But do you understand what happens behind scene? What additional technologies that they are using? And what partners that they are collaborating with?

    I have done some research on that and found out that some of the technologies that they use are not available publicly. Some of those companies are heavily funded and could pay a premium to the telecommunication companies in order to get the best location accuracy for the best user experience. I do not understand the details on how it works. I believe most of the location determination is actually on the server end (back end), not the mobile (front end).

    So, the apps that are developed by those companies not only can pinpoint the best accurate location but also does not consume a lot of battery.

    NOTE: I just want to share my 2 cents. The above information consists of my experience and personal opinion. It might not be 100% accurate as I am still learning Core Location and Region Monitoring.

    0 讨论(0)
  • 2020-11-28 03:56

    Sounds like even 1 meter should work (and work better on iPhone 4S+ devices):

    startMonitoringForRegion:

    (...)

    In iOS 6, regions with a radius between 1 and 400 meters work better on iPhone 4S or later devices. (In iOS 5, regions with a radius between 1 and 150 meters work better on iPhone 4S and later devices.) On these devices, an app can expect to receive the appropriate region entered or region exited notification within 3 to 5 minutes on average, if not sooner.

    0 讨论(0)
  • 2020-11-28 03:58

    I do agree with Michael G. Emmons, and want to share my experience too:

    I tested my code with three regions as shown in the image below:

    enter image description here

    Explaining the behaviour:

    • My current location is Region-1, and i start monitoring for the above three regions, and call to requestStateForRegion, to determine, if there is any region inside, where i am currenly standing.
    • Then i get "Enter" notifications, for first two region (region-1, and region 2), but it should only detect the region-1.
    • Now when i enter in region-2, i get the Enter notification for region-3. but i should get the notification for region-2 here.
    • Now when i enter in region-1 again, i get the Exit event fired for the region-3, and this continues.
    • but i don't get any Enter/Exit events for first two regions, until i move at-least more than 7Km-10Km far from first two regions.

    Expected Behaviour: - Enter/Exit event should be triggered only when i am crossing the boundary of regions, or inside the regions, not before 500 meter from the region.

    My Assumption:

    • What i have noticed after all the experiment, that when i call "requestStateForRegion" for all three regions,
    • it detects all regions inside region of radius 5000m, thats why it detects first two regions at the same time (region-1 create a circle of 5000m radius, and region-2 comes in its range, thats why region -2 is also getting detected).
    • and when user moves far more than 10Km, their Exit events will be called and when user comes back in these regions, their Enter event will be fired. Its the same case as explained by Aaron Wardle above.
    • Region-3 is getting detected, because,when user enters in region-1, ie. 8-9km far from the region-3, so Exit event is fired for this, and when user is on the route for region-2, here even when region-3 is 5000 meters far, still it detects the region-3 and fire, Enter event for region-3.

    So i think that all the regions inside 5000 meters are being detected, and as user moves away 10 km from detected region, its Exit event will be fired. otherwise if user is inside the 5Km range, it will never call it Enter/Exit events again.

    Please update me on, if anyone has fixed this issue, or Apple documents anywhere about this issue.

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