iOS get current location using GPS device - ios

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.

Related

Switching between significant-location-change monitoring and location-updates monitoring based on application state

We use significant-location-change monitoring to know about our user's whereabouts when the app is not running. This data is based on cellular towers signals and therefore is not very accurate. We would like to use more accurate data whenever it is possible, that is, when the app is active or running in the background.
The question is, should I use "startMonitoringSignificantLocationChanges" and "startUpdatingLocation" at the same time, or, should I switch between those two methods? And if the second option is better, what app delegate events should I use in order to perform the necessary switch?
Unless you want to support a feature that needs continuous high precision location stream, its best to avoid using the high accuracy GPS data via startUpdatingLocation all the time.
I understand from your question that you intend to use more accurate location only at certain points of interest, when your app is woken up. In that case, the second approach of switching-on the more accurate location data only when needed, would be a better idea.
locationManager(_:didUpdateLocations:) in your CLLocationManager delegate would be a good point to start this in your case. Remember that significant location change monitoring API wakes up the system at least once every 15 minutes, even if there are no location changes, until it is explicitly stopped. So one must use it with care.
Instrumenting accurate location tracking while making sure that you don't eat up all of the phone battery is a non-trivial problem to solve. You may want to give third party SDKs like Hypertrack, which specialise in this, a try.

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.

How does CLLocationManager get location?

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.

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.

CLLocationManager - Monitoring regions vs. Significant Location Changes

I am currently using significant location change updates to monitor whether or not the user has entered a particular area of interest (my definition of an area of interest is more broad than can be defined simply by geographic regions). My requirements are that my app should be woken up periodically to check if the user is said defined area (if it is not currently running).
My question is: would registering for region updates (since I have a number of regions that are known to fit my area of interest), provide me with more updates than simply listening for all significant lcoation changes, or would they simply be duplicate updates? The reason I ask this question is to clairify whether or not region monitoring is simply a filter on significant location change updates (since neither are documented as powering the GPS), or if region monitoring somehow is able to be more specific (maybe it powers the GPS, but with more specificity). In particular, I would be interested to know if anyone has seen data or documentation on this issue.
Thanks.
Region monitoring seems to pull from more specific location signal changes than the significant location change service. I say this because I've defined small regions (~100 m radius) that region monitoring picks up in the background, but that Significant location change does not. However please remember that the two events are triggered on different types of user actions.
Region monitoring - triggered on boundary crossings only. So a user must have two location update events on either side of the boundary. If you define large regions and the user walks around inside of them you will get no updates.
Significant location change - Seems to be triggered on the phone switching cell towers and the Location Awareness docs seem to suggest that. Here is some great data on general accuracy of these updates that suggests about 500 m between notification.

Resources