How does CLLocationManager get location? - ios

TL;DR:
My objective: Try all forms of getting a location and then choose the most accurate one, (try get a location for a minute then time out).
I'm a little confused about where it gets the location from, is it GPS? Cellular? or a mix of both depending on toolkit?
While getting location on Android I used both and then choose which provider based on accuracy. I do not see anything similar for iOS.
I'm using CLLocationManager which is showing good accuracy but I'm not sure where the location is from.

On iOS, location manager is built more intelligently. Relying on your configuration, it either uses GPS or WiFi/cell radios, as described in the CLLocationManager documentation:
For the services you use, configure any properties associated with
that service accurately. Core Location manages power aggressively by
turning off hardware when it is not needed. For example, setting the
desired accuracy for location events to one kilometer gives the
location manager the flexibility to turn off GPS hardware and rely
solely on the WiFi or cell radios, which can lead to significant power
savings.
For more information, read
CLLocationManager documentation.
EDIT
And, If you want the most accurate location, you should put kCLLocationAccuracyBestForNavigation for location manager's desiredAccuracy property.

Related

Why i am getting different locations name while i am at my home?

I am developing an iOS application to track user movement of the different location. I am using GPS to pull the user location[Alway from the setting location]. it works perfectly, but I am getting different location name while i am in my home.
Like in 1st bedroom you are 1503 location
and in 2nd bedroom, you are at 1702 location
how these different locations update works in background process?
It all depends of the service you are using with CoreLocation. You have here a list of the different services provided. The Standard location service (tutorial here) will be the most accurate and customizable but the less power friendly. CoreLocation often get you a location then update it to get you more and more precise location, the accuracy will also depends on the quality of your network.
You can customize the Standard location service with the following lines :
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.distanceFilter = 100.0 // In meters.
The desiredAccuracy is important.
But have you ever notice this?
When you're in a building and have WiFi turned on then CoreLocation uses WiFi to also pinpoint where you are.
How does identifying a location using WiFi work?
It's roughly something like this:
Imagine you that your building has 2 sides. Left side (1502) and right side (1702).
The left side has a wifi network named LeftSideOfBuildingWiFi
The right side has a wifi network name RightSideOfBuildingWiFi
At every moment your locationServices is turned on...Apple will capture the list of WiFi networks. It will say at 1502 the LeftSideOfBuildingWiFi has a stronger signal.
So now some other person enters the house and is connected to LeftSideOfBuildingWiFi or has stronger signal with that...Apple will conclude that you're likely at 1502.
This helps preserving the battery of the iOS device. WiFi consumes far less energy than the GPS chip itself.
The same is true if you're in the downtown. Yet if you're in the middle of nowhere in the road then it doesn't apply.
The same concept works for significant location services. They use cell-towers rather than GPS chip. Say there are 4 towers near to you and each one has a different signal strength. Likely you're closer to the one which has a stronger signal...
There is a lot of error in GPS readings. They get much less accurate when indoors, and can be off by 1000+ meters. Given that much error, it is not at all surprising that the location might geocode to different addresses when you are in different parts of a house.

What Does startMonitoringSignificantLocationChanges uses to Deliver Location

I want to Know what does startmonitoringsignificantlocationchanges uses to deliver location, is it GPS or Wifi/Internet? My Understanding is it uses cellular or wifi,to know if device has moved significantly but what I don't know is, at time of picking location does it use GPS alone to pick up location.
My Findings are : I travelled 30 KM in City Train but did not get any locations in background and during this journey my Wifi and Cellular data was off. So please tell if Significant fails to provide locations based on GPS only.
Building location apps in the past, I assumed that GPS was only used when startUpdatingLocation() was called. After double-checking the docs, Apple doesn't explicitly state whether significantLocationChanges CAN use GPS, but it is a power-saving option, and their docs specify that it "requires the presence of cellular hardware", which makes me pretty certain that my assumption (and yours) are correct. I'd leave this up for a bit, in case there's a hardware expert who knows for sure. The docs you want: https://developer.apple.com/reference/corelocation/cllocationmanager
Like all location functionality, it uses a combination of cell, wifi, and GPS. Use of cell is primary. The idea is to keep use of GPS to a minimum, in order to prevent drain on the battery.
You certainly cannot expect this to work with the cell turned off; indeed, if your code properly checks significantLocationChangeMonitoringAvailable with the cell off, I would intuitively expect the answer to be false.
(Also note that you will not get any events unless you have a location manager with a delegate.)
As explained in this answer "Hows does Significant Location Change work?" (and in WWDC videos from 2013-2015) Significant location change monitoring uses a technique called Cell Tower Triangulation.
You can think of it as almost the same mechanism as GPS triangulation except that the cellular hardware will be used to gauge distance from nearby cell towers instead of firing the GPS hardware to get signals from actual satellites.
In my experience I've noticed that this method gives accuracy of approx. 1000m. It does not use the GPS hardware and hence is more battery efficient. It is good for coarse location updates. See WWDC 2013 session Harnessing iOS to Create Magic in Your Apps where the presenter makes a passing reference to this technology.

Switch btw. Location Manager & Region Monitoring

for an app that is part of a scientific study I have to implement location tracking (the users who take part in the study know this and are willing to supply this data). The two premises for this app are:
track the user's location with the highest accuracy possible while he/she is on the move
use as little power as possible so that users don't feel the need to shut down the app (turn off location services for it), while they aren't using it
I know these two requirements normally exclude each other :) So the general question is "What would be the best strategy to meet in the middle here?"
My thoughts were to monitor as usual with the highest accuracy possible while location changes keep coming in. If we detect that the delta between theses location updates become almost 0 over a certain period of time, we would assume that the user is not "on the move" anymore and would switch to region monitoring (with a radius of e.g. 40m). Once the user exits that region we'd switch back to regular location monitoring.
So two questions:
Can you tell me if the proposed approach will work for an app that is running in the background?
Have you maybe implemented something similar and know if it really saves a lot of battery power?
Regards,
Sebastian
My thoughts were to monitor as usual with the highest accuracy possible while location changes keep coming in. If we detect that the delta between theses location updates become almost 0 over a certain period of time, we would assume that the user is not "on the move" anymore and would switch to region monitoring (with a radius of e.g. 40m). Once the user exits that region we'd switch back to regular location monitoring.
Using region monitoring to re-engage the location monitoring has a few draw backs, that I have found:
If you set up a region for the user's current location, then wait for -didExitRegion to fire, you're reliant upon the system's default radius cushion, (probably 200m) and some time (probably 20 sec) after they cross out of their boundary before you'll get the message. If accuracy is your main goal, you're likely to loose a lot of data points in between when region monitoring started and when you cross out of the region. Is that acceptable for your needs?
So, to answer your questions:
Can you tell me if the proposed approach will work for an app that is running in the background?
You should not have any trouble running this type of thing in the background. Both location monitoring and region monitoring work when an app is backgrounded, provided you've set it up to do so. Also, to ensure Region Monitoring works on iOS 7 you must have Background App Refresh turned on for your app. That tripped me up.
Have you maybe implemented something similar and know if it really saves a lot of battery power?
In our experience the battery savings were not noticeable. Region Monitoring can be a battery drain that's just as significant as the high accuracy location updates because it uses all kinds of hardware to do it's thing. So pick your poison. Apple's recommendation for saving battery is and always has been to use the significant change location service. It gives you good location data just not as often.

Does the accuracy property influence the accuracy of mapview.userLocation? [Titanium]

I'm using the mapview property userLocation to show the users location on a map. Does it matter what value Ti.Geolocation.accuracy has or is the accuracy of the position marker (as it is a part of the map app) only influenced by the map app?
If it's latter: On Android I (as a User) can choose only between wifi/gps accuracy. Is the accuracy controlled automaticly (e.g. according to the battary charge)?
It seems that accuracy settings only apply to the Geolocation module. According to this thread, these settings have no effect on the user location accuracy on map views.
Based on the accuracy you choose, iOS uses its own logic to select location providers and filter location updates to provide location updates that meet your accuracy requirements.
Also remember: Location services stay enabled for as long as a listener is registered for the location event, so be sure to remove the event listener when you do not require location updates.
You can read more about it in Titanium.Geolocation documentation.
Rule of thumb is not overusing accuracy level when you are accessing user location. Be nice for your users and their devices. If your app will drain their battery in minutes they will remove your app and never come back to it.

iOS get current location using GPS device

I want to use CLLocationManager to get the current user location using GPS antenna, not the cellular network. How can I ensure that?
Your choices is either the standard location service (e.g. startUpdatingLocation, for which you can specify the desiredAccuracy), or the low-power significant change service (e.g., startMonitoringSignificantLocationChanges). But you generally don't specify location services based upon hardware, but rather on the basis of your app's functional needs. Use the standard service if you need an accurate location, and try using the significant change service if you don't need the same level of precision.
See the Location Awareness Guide for more information.

Resources