Add more than 20 regions to geofencing ios - ios

I want to add 100 of regions to geofencing.(apple limit it to 20)any one have better idea for it.please help me.
currently im using significant location change.when significant location change,
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
method i call API with current location and get the nearest region set and add into geofencing.This method works.But i heard from web significant location change fire depend on the cell towers.If there less cell towers then it will be problem.Other thing is when calling api in background it will be effect to the battery.

Related

CLLocationManager desiredAccuracy of kCLLocationAccuracyHundredMeters causes location updates to be very infrequent

I am attempting to use location accuracy of kCLLocationAccuracyHundredMeters for my standard location updates in my application, which seem to work relatively well for a bit, but every once in a while I will receive a 10 minute gap between updates (while driving around multiple miles in different directions) which seems out of character for the setting. Here are the settings on my location manager. Also I am only using foreground location updates so for these tests I had the screen on the entire time and app always in foreground.
self.locManager = [[CLLocationManager alloc] init];
self.locManager.delegate = self;
self.locManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
self.locManager.distanceFilter = 15;
I tried out kCLLocationAccuracyBest with the same other settings and I get perfect measurements throughout my drive, but I don't need that accurate of a location. I assumed the hundred meter accuracy would still give relatively consistent updates with less accuracy, which is what we are looking for.
Is this just a side effect of working with the kCLLocationAccuracyHundredMeters setting vs kCLLocationAccuracyBest?
Tested on an iPhone 6s : 11.0.2 and iPhone 7Plus : 11.0.3
Any help is appreciated, thanks!
EDIT:
I should clarify I did setup logging in the CLLocationManager delegate methods listed below, but never received any callbacks / logs.
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
- (void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(nullable NSError *)error;
- (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager;
- (void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager;
When you ask for kCLLocationAccuracyHundredMeters iPhone does not use GPS at all and relies on cell towers and wifi access points for triangulation. That means iPhone updates location with the frequency of wifi scans, which is far from continuous. If you are getting away from areas with wifi coverage, cell towers become your only source and you might start getting location updates only when switching between cell towers.
To cut it short:
setting accuracy tells iOS which hardware to use,
distance filter tells iOS how far to move before waking up CPU with new data

Beacon - StartRanging and stopRanging depend on the Beacon Proximity

Can somebody help me how to solve the issue.
My current beacon setup :
Beacon device - Estimote.
UUID - same for the two beacons.
I have placed each beacon in two rooms, rooms are 20-30 Meters away from each other
I'm hitting webservice and updating something (when the proximity is near or immediate) when i enter a specific room (checking if major and minor of this room actually belongs to this room)
3.It also hits another webservice and updating something (when the proximity is far and unknown).
Problem with the current algorithm:
1. When i enter room 1 and if it is near or immediate, it hits webservice1. When this happens, room2 proximity will be far or unknown, then again webservice2 is hitting and also there are lot of fluctuation. Sometimes when i'm in room1, room2 beacon proximity shows as near. I don't this to happen
New Approach and Questions
I would like to Monitor for specific region , say room1 when i'm near say 5 meters away, and start ranging the beacon only when proximity is near or immediate. and stop ranging when proximity is far or unknown or i'm more than 5 meters away
When i move near to room2 (5 meters away) and if the proximity of room2 is near or immediate, it should start ranging room2 and stop ranging room1
I would like to have clear approach or way to write algorithm to achieve the above. Calculation can be using the proximity or using some other idea (like combination of RSSI and proximity or something else)
It would be great if you can explain me in detail with example on how to achieve the new approach or you can tell me if there is any other better approach, but please explain with code.
My foremost concern is, it should't range room 2 beacon when i'm in room1 or just 5 meter away from room1 and vice versa.
Have you thought about putting each beacon in its own region? So room 1 would be a region, and room 2 would be another region.
After that I would make use of locationManager:didEnterRegion: and locationManager:didExitRegion:. Within these, you can start and stop the ranging of your two beacon regions depending on which room you are in.
Please note, the Apple Docs state that:
When testing your region monitoring code in iOS Simulator or on a device, realize that region events may not happen immediately after a region boundary is crossed. To prevent spurious notifications, iOS doesn’t deliver region notifications until certain threshold conditions are met. Specifically, the user’s location must cross the region boundary, move away from the boundary by a minimum distance, and remain at that minimum distance for at least 20 seconds before the notifications are reported.
The specific threshold distances are determined by the hardware and
the location technologies that are currently available. For example,
if Wi-Fi is disabled, region monitoring is significantly less
accurate. However, for testing purposes, you can assume that the
minimum distance is approximately 200 meters.
EXAMPLE:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
if (region.identifier == YOUR ROOM 1 IDENTIFIER)
{
//Start ranging room 1
}
else
{
//Start ranging room 2
}
}
- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region
{
if (region.identifier == YOUR ROOM 1 IDENTIFIER)
{
//Stop ranging room 1
}
else
{
//Stop ranging room 2
}
}
The core problem is sending info to the server at inappropriate times. It really has nothing to do with starting ranging.
You cannot start ranging when proximity is relatively close -- you have to range in order to determine proximity.
Rather than an algorithm that starts and stops ranging, I suggest you simply leave it on all the time, and build a filter that decides when to make the server calls. Here's a starting point for the logic I would suggest:
Call the server if all the following are true:
beacon.accuracy < 3
all other beacons detected have beacon.accuracy > 3
no server call has been made for this beacon recently
EDIT: You can reduce the fluctuation on the accuracy reading by setting your beacon transmitter power as high as possible to maximize the signal to noise ratio.

Play audio for directions using MapKit inside an ios app

I am developing an ios app that has MKMapView embedded. And the app shows route from current location to the destination. I have managed to do this.
Can we play audio for step by step route inside our own app? Does apple provide us some libraries so that our app can play the instructions? How can this be done more efficiently
Thanks in advance.
Here are steps you can follow to achieve this.
Store Coordinates of all the step endpoints.
Store direction instructions of individual step.
Inside the method,
(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations;
compare the distance of your current location with the current step start coordinates. And if the distance is within some limit, say 50 meters, you can play the audio.
I am not sure Mapkit provides you the coordinates of individual step coordinates. However, Google map sdk for iOS does provide all the coordinates of each route points.

How to increase iOS map location update rate to 10 times per second?

I'm doing a pedometer application and use CLLocationManager to update user's location. but the delegate's method "- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations" update rate about 1 time per second. I want to know if some code can increase update rate greater than 1 time per second. I would be very grateful.

Toggling wifi on and off trips local geofences in iOS7

My app is monitoring around a dozen circular regions at a time. Region monitoring works as expected most of the time. However, I have noticed that often when I toggle wifi on and off from the settings or control center,
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
is called for all regions, regardless of size, within several miles of a my current location.
Anyone know why this might happen, and if there is a way to filter out these false positives?

Resources