Geo Fencing functionality iOS 11 - swift

I am working on Geo fence with Google map. My question is about the minimum radius for CLCircularRegion. As I want to work with the region for 30 meters. But the functionality works for the 100 meters. I have searched a lot and found that Apple needs minimum radius 100 to create a region, no matter I have set 30 meters or 50 meters.
Here is the link -
Geofencing iOS 6
Moreover, didEnterRegion call at 100 meters and didExitRegion works very oddly and took much time.
I have also read, that it depends upon tower cells etc according to that these methods call.
Here is the link -
What is the maximum and minimum radius that can be set for regions in iOS geofencing.
I want to know if I have set the region for 50 meters. Why it is not working as per required region radius. In fact, I observe that it is working for the radius 100 meters.
Here is the code:
func createRegion(lat : CLLocationDegrees,lng : CLLocationDegrees) -> CLCircularRegion?
{
let latitude = lat
let longitude = lng
var radius = CLLocationDistance(50)
if radius > locationManager.maximumRegionMonitoringDistance
{
radius = locationManager.maximumRegionMonitoringDistance
}
let region = CLCircularRegion(center: CLLocationCoordinate2DMake(latitude, longitude), radius: radius, identifier: "TEST")
region.notifyOnEntry = true
region.notifyOnExit = true
return region
}
Or also can anyone refer a good app that has Geo fence functionality. So that I can compare my app's accuracy with it.
Question: I have selected 50 meters radius and 'upon exit' notification should come. But I am getting a notification on/around 250 meters and some time more than this. Please help me out
Thanks!

Take a look at Apple`s developer documentation:
Article Apple
Official Documentation
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.
And remind that if the Wi-Fi is disabled, then it will be less accurate.

I think you can reverse engineer the minimum radius on your device by looking at the device logs in Console. For example, if I set a radius of less than 100m on my iPhone 8 with iOS 14.7, I get the following log statement:
Fence:Start Started monitoring fence myapp/<private> (<<private>,<private>>, radius 100.000, active tech <private>)...
So, 100m seems to be the minimum in my case.

Related

Swift: Coordinates not accurate when using latitude/longitude

I'm using the CLLocationManager in Swift.
When I display location.coordinate, it provides me with the result:
37.787358900000001, longitude: -122.408227
However, if I display. location.coordinate.latitude, the result is
37.7873589
Do you know how I can get all the decimals?
Thanks,
Thomas
You are seeing 37.787358900000001 instead of 37.7873589 because of the nature of representing floating point numbers in a computer.
That said, it is pointless to worry about decimal places beyond the 6th position because even changing the 9 to an 8 would result in a change of about 1 centimeter. The GPS system is currently accurate to about +/- 5 meters, and with new chips being deployed by Broadcom that can be reduced to about +/- 30 centimeters in the near future.
By the way, do you know why the altitude keeps updating/changing, even
when the device is standing still on a table?
Altitude calculations are done by computing the distance to the visible GPS satellites which orbit the Earth every 12 hours. Since the satellites are constantly moving, and different satellites come into view, these calculations do tend to fluctuate. This article though a bit dated is enlightening.

Geo Fencing Identifier

How to specify the entire country as a region in region identifier.Wether it will accept the
identifier as :#"Uk"
here the code to reo identifier.How can i specify England or UK.Please help me to sort out
CLLocationCoordinate2D location2D = mapView.region.center;
CLRegion *regionForMonitoring = [[CLRegion alloc] initCircularRegionWithCenter:location2D radius:1 identifier:#"RegionIdentifier"];
[[Utils getLocationManager] startMonitoringForRegion:regionForMonitoring];
CLRegions are totally unsuitable for this purpose.
First of all, the radius specified is the distance in meters that the region covers - so in your case you are asking the system to monitor a region at a specific lat/long with a radius of 1 meter!
Also, system regions have a maximum number of regions that can be monitored (around 10 or so), and a maximum radius that can be used of around 400 meters after which the region will not work.
You really need to read the "Monitoring Shape Based Regions" section of this Apple document:
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html
There are two other possible approaches to what you are trying to do:
1) Use Significant Location Updates, and test on each update if you are in an area with a shape you specify.
2) Use CoreTelephony to look up the cell carrier your device is on and see if the carrier number matches one in the country of interest. Of course, this will not work on some iPads or other iOS devices with no cell connection.
Neither of those approaches will be exact around the edges, but will also not consume nearly as much battery life as using the GPS.

cllocation -distanceFromLocation bad accuracy

i am developing an app which is particularly dependent upon the distance between two iOS devices. I am using GPS location of devices to calculate the distance between them.
To calculate distance, i am using cllocation -distanceFromLocation method but the values generated by method is fluctuating and differs from actual distance between devices and cannot be considered even as an approximate result.
For example, if the actual distance between devices is 2 to 3 meters, it gives me the result around 14 meters at some point and 43 meters at another point. Is the the function -distanceFromLocation: is not so precise and accurate????
Is there any better alternative for calculating distance using GPS latitude and longitude of devices???
Please help me out.
Thanx in advance.
The accuracy of CoreLocation GPS varies greatly depending on your surroundings.
At it's most accurate it can go down to a couple of metres resolution (I'm not sure exactly) but if you're indoors it will be more like 20-50 metres.
I'm guessing that you're developing and testing the app indoors and so the fluctuations would be about normal.
Even outdoors in perfect weather CoreLocation will struggle to accurately tell you the distance between two devices over a short distance. (i.e. a couple metres).
For short range you might be better using wifi signal strength instead. Although this can also change from room to room.
Essentially, it's difficult to accurately detect the distance between two devices.

How does my iPhone get its altitude?

I made a simple app which displays the altitude according to the GPS position on iPhone.
How is the altitude obtained?
Does it get the altitude of the land at the coordinates I am or does it get the actual altitude? (I tried the same application in the same building; once at ground floor and once on the third floor but the same altitude is displayed)
Is it possible to obtain a different altitude on different floors? (Like my android phone has a barometer sensor and I calculate the elevation by the atmospheric pressure; but none of the iPhones has a barometer sensor)
The altitude as read by the gps receiver depends on the positions of the satellites over the horizon, relative to each other. It is possible then for the altitude reading to be unreliable when either there are not enough satellites in the sky or they are too close together. This then depends on the time of day, or date.
The signals from the satellites are very weak once they have reached the Earth's surface, and may not be received correctly inside buildings, or where there are other tall buildings nearby, such as a city centre like Manhattan.
Barometer readings will vary according to the weather and so an absolute reading can't be applied to a specific floor. However relative readings may be reliable enough for floor to floor changes, e.g. a lower value means going up.
Like any other device that uses GPS to calculate altitude, it's measuring the user's distance from the center of the satellites' orbits.
Your smartphone uses GPS technology to calculate your altitude depending on where you are. It measures how far away you are from the satilites which is calculating this information.
Note that newer IPhones (>= 6) have a barometer sensor which in my experience is significantly more accurate than GPS. With a barometers the accuracy appears to be within a foot whereas with GPS it would bounce around by 3-4 meters even when standing still.
http://www.iphonetricks.org/iphone-6-barometer-sensor-features/

Minimum accuracy of startMonitoringForRegion in meters

I've encountered problem with startMonitoringForRegion method in iOS 5. Documentation says that method is taking parameter "accuracy":
- (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy
I'm currently developing an app that should notify user when he's in 25 meters radius from monitored point. App uses GPS with kCLLocationAccuracyBestForNavigation setting. I'm creating (CLRegion *)region like this:
CLRegion *pointRegion = [[CLRegion alloc] initCircularRegionWithCenter:pointLocation radius:25.0 identifier:identifier];
and setting accuracy parameter in startMonitoringForRegion for kCLLocationAccuracyBestForNavigation.
Region monitoring works well in my app, however didEnterRegion method fires when user is around 100 meters from monitored region, not 25 meters.
Is there minimum value of radius in startMonitoringForRegion that is not described in Apple's documentation or am I doing something wrong? Is it possible to set region monitoring to relatively small values (like 5-25 meters)?
You cannot set iOS Region Monitoring to lower values unless turning on significantLocationChanges. It's only working in US in bigger cities because region monitoring is based on cellular network.