How to get location by GPS without network in iOS? - ios

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.

Related

Significant location change doesn't work on Wifi only devices

Correct me if I'm wrong, I have two devices (iPhone), one with sim-card included and wifi connected, other doesn't have an active sim-card but connects to wifi. I was on train to test the significant location change on both devices, only the one with sim-card sent significant location change event. The one without sim-card didn't fire any event even though it still connected to Wifi.
Any link references are appreciated. IMO, does the significant location change only work with cellular data ?
I believe the significant location change updates location only when the phone swap from a cellular tower to another, so if it is not on the cellular network (without sim card) it can not detect that, and therefore cannot provide a position :)
From Apple doc:
The significant location change service is better suited for apps that want to get the user’s initial location and then only want to know when that location changes. This service requires the presence of cellular hardware and delivers events less frequently than the standard location services.
Source

Significant-Change Location Service will use Wi-Fi or Mobile Data?

When use Significant-Change Location Service it must use Wi-fi ? Without Wi-fi this service will work or not?
Theoretically it should work but location mechanism is a bit complicated in iOS.
iOS devices uses a system called aGPS. Which relies on combination of gps, cellular, wi-fi, geofencing etc. Wi-fi is the fastest location update option for the location manager since you can get your accurate-enough information immediately. GPS is the most accurate one but it takes couple of minutes to lock and determine your location if you changed your location a lot since the last lock on.
So maybe you had an impression that when wi-fi is disabled significant change location service doesn't work but actually it does. At least this is the expected behavior.

iOS devices without Internet to capture current location

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

Detecting tunnels with Core Location

I am using Core Location for turn by turn based navigation and would like to show a "GPS lost" alert in tunnels.
The problem is that the following two scenarios look the same to the app:
The user drives into a tunnel. GPS updates cease because there is no way to know where the user is.
The user stops at an intersection. GPS updates cease because the user is no longer moving.
I need to set these two situations apart. Ideas?
I have tried looking at the horizontalAccuracy property, but sometimes the updates cease completely, so there is no new horizontalAccuracy information.
Normally with CLLocationManager set for best accuracy for navigation and no distance filter, you should get a location update once a second even if you are stopped at an intersection.
If you stop getting those updates while the motion coprocessor (using CMMotionActivityManager) says you are still driving then you can infer that you are in a tunnel (or underground car park or someplace with a bad GPS signal).
BTW, GPS updates should not stop when you are stopped at an intersection if you have set distanceFilter = 0 and desiredAccuracy = kCLLocationAccuracyBestForNavigation and activityType = CLActivityTypeAutomotiveNavigation, etc.
Another thing to watch out for, if the tunnel has cellular coverage, you may still get location update from cellular triangulation but with worse accuracy. If the CLLocation.horizontalAccuracy goes from less than 50m to over 300m then you have lost GPS/GLONASS coverage even though you are still getting location updates.
Look at locationManager:didFailWithError: method:
If the location service is unable to retrieve a location right away,
it reports a kCLErrorLocationUnknown error and keeps trying.
To determine a second situation (user stops) use locationManagerDidPauseLocationUpdates: method:
When the location manager detects that the device’s location is not
changing, it can pause the delivery of updates in order to shut down
the appropriate hardware and save power. When it does this, it calls
this method to let your app know that this has happened.

In ios, is it possible to know if the GPS location is not being updated?

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."

Resources