As far as I have searched, iOS devices without internet (WiFi) are struggling to acquire current location when GPS is the only option.
Is it possible to get current location in that situation, I mean using only GPS?
Sure it does automatically, if no WiFi is enabled it should automatically trigger the GPS, it takes a long time because if no location data is cached it starts to search for satellites.
If you want to display and error message, you can use a timer, if after X seconds no location is obtained just stop updates and show an alert to the user.
A great difference in time is made by the desiredAccuracy, if you set a lower accuracy even if when the GPS is on it will require less to get your position.
what do you mean by struggle?
Is it possible to get current location in that situation, I mean using
only GPS?
yes, perfectly
Related
I am creating an app that uses a lot of gps location. If a user's phone settings allows for GPS, is it ever possible if their initial location is "
None"?
The reason I ask this is because when I simulate the app on the simulator, the default setting for location is "None" (Which causes some bugs). I want to know if these "None" locations only affect simulators or if they should be accounted for.
Yes.
You have to handle this case.
A user can have an issue with his device GPS or not allow access to it or GPS takes time on load to get the first location for some reason.
You can't expect any perfect scenario, deal with None.
I want to know if these "None" locations only affect simulators or if they should be accounted for.
You should design your app to be able to tolerate not getting a location even if you're sure the device has the necessary hardware and the user permits the app to get location data. There will be times when the device simply can't get a location fix, or when the hardware fails, or the battery is so low that the system chooses not to turn on the radio, or whatever. You can't ensure that all the things that could go wrong won't, so make sure your app is prepared to handle problems.
this "None" location would need to be handled in multiple places -- I don't want to add unncessary code
That sounds like a different problem. If you have more than one part of your app getting location data... why? Make location processing part of your app's data model. That way you're only receiving the location in one place, and you can handle problems in one place, and any other part of the app that needs the location data can get it without having to reimplement all that stuff.
I've got a concept of adding feature to my app which will register user location in interval of few seconds. Then sending this coordinates through cellular or Wi-Fi all when staying active in background. I need to send this in almost real time, so the app can't be killed in backgorund.
I know this concept is very power consuming but it is only a conception.
The conception of getting constant location in backgorund is in this theard https://forums.developer.apple.com/thread/69152
so I think it is possible.
But refreshing only the process in my app of sending coordinates to server it's a little bit difficult. I could not get straight answer that it is possible to set the time interval in which the app will refresh in backgrund.
Is there a method for telling the app how often it should refresh in background?
Apple won't let your app idea onto the app store. They're quite strict about which types of apps are allowed to run in the background, and are allowed to use continuous GPS. (Both of those things really drain the user's battery.) Sending a continuous stream of location updates to a server will also keep the cellular/WiFi transmitter powered up, making things even worse.
For your own experimentation, though, you can probably set up your app to be a navigation app. Those are allowed to keep the GPS "lit" constantly and to run in the background. You could then set up the location manager with the highest accuracy setting and start updating your location.
I don't think you have the ability to control how often you get location updates though. You could create a timer that fires on a regular interval and fetches the current location from the location manager. However I don't think there's much value in that, since you WILL get called when the user's location changes, and fetching the current location more often will just give you the same answers repeatedly.
I use CoreLocation Framework to get location, when in network it work normal , but when without the network, it can not locate always. it will not stop receiving location information after seconds. I want to know how to use GPS locating without network?
I think you are using your device in a house or building, where the device can't receive GPS satellite signal.
If that's the case, what you are seeing is the expected results. iOS internally keeps the last location (cache). When you start location updates, iOS passes that cashed location quickly to locationManager(:didUpdateLocations). When no network nor satellite signal, no location update will be sent thereafter.
If your device is receiving wifi w/o satellite signal, iOS determines the rough location by using the wifi, and sends location updates. You can't distinguish the source of location updates; they could be from wifi or from GPS satellite. (actually, you can guess by seeing the accuracy. when the source was wifi, accuracy was fixed to 50m w/ my iphone.)
One way to check if your location update is cached or not is to check the time stamp of location update.
The cashed location update should have older time stamp than when you started location update.
So, to your question, you are doing just right thing. Location manager is very easy to use. Try to receive satellite signal in open sky w/o network. For your tests, don't move. It may take 5-7 minutes at most. If you move, it may take longer. Hope this helps.
I'm creating an app that allows the user to navigate with a map when offline (no internet connection or wifi available), and I want to let the user know if the gps location not being updated. I know I can get the last updated location timestamp and the accuracy, but is it possible to know if the gps has no reception?
No, there's no public interface for finding out about the state of specific location hardware such as the GPS receiver.
The Location Manager abstracts all that away, so that developers can get location and accuracy information without worrying about whether the device used GPS, Wifi, iBeacons, cell tower locations, Loran-C, celestial navigation, etc. to determine the location. This is generally a very good thing because it means that your apps work on all devices regardless of whether they have GPS, and will continue to work (and maybe even work better) on new devices that might use other technology. But it also means that you don't get to ask the question "is the device receiving a GPS signal right now?"
Is it possible to know if the GPS location is not being updated?
No. It doesn't seem possible given the available API.
There are a few things about GPS to consider, if you haven't already. It is technically possible to receive a location update from CLLocationManager when you're "offline" but it will depend on several things:
If your device actually has GPS hardware. Some don't.
If you have line of sight to GPS satellites. There's a difference between GPS and A-GPS
Those true GPS updates will come much less frequently because of the way GPS works, but it should work.
... but is it possible to know if the gps has no reception
Based on the way GPS works (as best I understand it) you either turn the radio on/off (-startUpdatingLocation/-stopUpdatingLocation) with the Location Services API and you either get locations more frequently with A-GPS or infrequently with pure GPS when you don't have a network signal. I don't think the Location Services API has a way of telling you "I don't have a GPS signal at all."
I am testing some GPS algorithms with the battery life. I just wrote a very simple app using core-location framework and the app update the gps location every second.
I am wondering how can I change the time interval to update my location, like 10s, 1min, etc?
And when my app is at the background it's stop updating the GPS, do you know how to keep it updating at the background?
be aware that iOS usually does not allow background operations in most cases.
But at least there are three options to "permanently" determine the location:
As you wrote: determine location all the time when your app is not in background. (1)
determine location all the time - also in background. You need to update your Info.plist and add location as a required background service (required for location tracking, Google Latitiude for instance) (take a look at api)
get location updates only when the location changes significantly.
You are not able to change time intervals or something like that. You only have theses three options - and you can get location information only once when you need them, but that was not the intent of your question.
I am wondering how can I change the time interval to update my
location, like 10s, 1min, etc?
This is not possible and it would not make sense, because the GPS chip needs the same power if it a position is needed once a second or evry 10 seconds. Of course you can ignore positions if you dont like them (if they come to often).
The settings of desiredAccuracy influences the power:
kCLLocationAccuracyBestForNavigation: enabled GPS and Acceleration sensors
kCLLocationAccuracyBest: enables GPS but no Acceleration sensors (Cell Tower locating if needed)
kCLLocationAccuracyHundredMeters, kCLLocationAccuracyKilometer, kCLLocationAccuracyKilometer: more likely to use Cell Tower or Wifi locating if available.
That uses less power (more likely) but accuracy is lower.
And when my app is at the background it's stop updating the GPS, do
you know how to keep it updating at the background?
If your read Apple's LocationAwarnessGuide ypou find the info, how to set the correct key in Info.plist file.
Since ios 6 there is an additional variant, which should save more power:
There is the method: didUpdateLocations (note: plural!):
This will deliver all locations at once such that it ios does not need to keep your application living in background. Once the app enters foreground you will receive all positions at once.