Why couldn't I get GPS coordinates in a remote place? - android

I went on a trip somewhere remote and I didn't have mobile access but I thought that my GPS would work anyway since a GPS transmitter just relies on satellites. I have the following code to get GPS location:
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
I tried to record my GPS coordinates and they ended up empty.
Is there something that I am not doing correctly or that I don't understand?
What can I change so that my phone can record raw GPS data with or without network access?

A GPS receiver needs to have several GPS satellites above the horizon, in order to receive the signals it uses to calculate its longitude and latitude. Each satellite broacasts this ephemeris information as part of its data stream, but a standalone receiver might take several minutes to scan through the available satellite frequencies from a "cold start" (where cached ephemeris information is out of date or incorrect for the current location).
GPS receivers on cell phones often implement "carrier assisted GPS", where the cellular network pushes the up-to-date GPS satellite ephemerides out to the handsets from time to time, so the phone already knows which satellites are in view at any given time/location without having to do a search.
If you don't have cellular network access, your phone might be programmed to fall back to a satellite-by-satellite search for usable signals, and might take longer to get its first GPS fix (if it can get one at all without carrier assistance).

Related

Does Location Services' `getLastKnownLocation()` check phone's current GPS location?

Some resources say getLastKnownLocation() merely gives a location of some previous app's Location Change Listener.
But one thing I feel is missing from the conversation -- if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves? So if I call getLastKnownLocation(), isn't it getting the current GPS from the phone's constantly-updated GPS?
If so, then why do people warn against using it / accuse it of potentially getting a "stale" location? If the GPS is being tracked / updated, and getLastKnownLocation() makes a one-time grab of it's current position, what makes getLastKnownLocation() bad?
What am I mistaken about the Locations service or GPS?
The documentation says: Returns a Location indicating the data from the last known location fix obtained from the given provider.
Also, about the "out of date location": This can be done without starting the provider. Note that this location could be out-of-date, for example if the device was turned off and moved to another location. ("This" refers to getting the last known location).
Also, taken from LocationProvider docs:
Each provider has a set of criteria under which it may be used; for example, some providers require GPS hardware and visibility to a number of satellites; others require the use of the cellular radio, or access to a specific carrier's network, or to the internet. They may also have different battery consumption characteristics or monetary costs to the user.
if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves?
Well, it is, but not constantly. This has to do with battery consumption, if the phone was constantly updating the GPS location, the battery life would suffer a lot. The GPS location is usually updated when some app requests it. But even that request is not guaranteed to succeed. For example, suppose your going into a tunnel. Some application requests to update the GPS coordinates right before entering the tunnel and it succeeds. Now, you've entered the tunnel, which is 5km long. Most probably your device won't be able to get a GPS fix from the tunnel, so for the next 5km (at least) getLastKnownLocation() will return an outdated value, since the devices last known location was at the entrance of the tunnel.
What you could do is explicitly request to update the GPS location, that however might take some time and there are no guarantees that it will succeed.
You have the assumption "if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves". This assumption is incorrect. The GPS functionality takes up a lot of battery life so it should be used sparingly and almost certainly not all the time.

Android GPS location isn't as accurate as network location

I've got an app which sets up two location listeners (one for GPS and one for network) and then chooses the location from the best one available, which should be GPS. However, if GPS is turned on, it will always choose the GPS location, even if the person starts the app up indoors. This has led to the GPS location being used even if the last known GPS location is from miles away and the network location is actually much more accurate.
Is there any way around this issue or is it just something that will need to be accepted as an issue with using GPS & network? Is the standard practice just to assume that GPS is always more accurate even though it's possible that it might not be in certain instances?
If you are using the network provider to fetch the location they are not very accurate when compared to GPS. So it can be a good idea to fetch the accuracy of your position using network provider when you are indoors as GPS doesnt function well indoors and you can use GPS to get the location updates when you are outdoor.
You can use GetAccuracy() method of Location class and see for the value it returns. Let Say if getAccuracy() retruns 25 then you can leave this value wait for another gps value until you get the desired value. Remember the value it returns is the radius of the circle in meters.

get coordinates without gps (android)

I'm developing a android app and I want to receive coordinates from a smartphone. Two questions:
1: GPS is enabled, but there is no signal, so I have no coordinates. How can I check, if GPS is sending coordinates or not?
2: If GPS is enabled and there is no signal, which other method can I use to get the coordinates from the smartphone?
Getting coordinates requires using the location services, which by default uses all manner to determine location, not just the GPS, but cellular signals as well. Here is a tutorial on using the location services in Android.
One word of advice - if you are going to use GPS and generally distribute your app, know that the GPS service is VERY battery intensive. It requires judicious coding to not drain your users battery. You have been warned!
1) fetch device coordinates using locationService.
mContext = getActivity();
mLocationManager = (LocationManager) mContext.getSystemService(Application.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(mProvider, 60000, 100, mAttLocationListener);
boolean gpsEnabled = mLocationManager.isProviderEnabled(mProvider);
2) You can still get rough estimates using location information stashed in wi-fi

Experience of Location Services on Android using GPS and Network providers

I have written a piece of code to get a feel of what my customer (cab driver) will experience when I enable location services on his device for my cab booking application. I enabled location services using both Network and GPS providers on the same listener.
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
// God.KM20TIME, God.KM20DISTANCE, (LocationListener) updates);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, God.KM20TIME,
God.KM20DISTANCE, (LocationListener) updates);
My battery ran out much faster than normal. I also had my phone heating up more than normal. But the consistency I was expecting was really low. I have decided to not use GPS, and only Network provider. I am building a cab booking app, so I need to know where the cab is approximately. Even if I know that the cab was at a approximate (300 meters) location about 15 mins back, I should be good. So I guess my decision to not over engineer this logic by using both providers is correct. I wonder if anyone can relate to a different experience here ? Am I missing something ?
From my experience, the quality of the Network provider can vary quite a bit.
The network provider uses a combination of WiFi and Cell tower information to provide location information.
If you happen to be close to a Wifi network, which is common in urbanized areas, but not outside of cities, you usually get a very good accuracy.
However, outside of range of a Wifi, you're at the mercy of the cell towers. Here, the precision depends on the quality and features of the cell tower, as well as the amount of cell towers that can be used to triangulate your position.
In these situations, the quality can vary alot, both between locations, but also depending on which Carrier you use, the distance between their cell towers, but also what make and generation of cell towers they have. Newer have more features regarding location, and might for example provide bearing on its own.
My application runs in Sweden, and in some areas of our country, a carrier might have only one tower within a very large area. In those cases, all lon/lat fixes end up directly on the tower, with a precision of even up to 20.000 - 30.000 meters.
Basically, my point is that when using the network provider, if you're not near a Wifi, i'd be very satisfied with 300 meters accuracy.
Regarding the battery / heat - with your requirements, you can play around a lot with the time / distance parameters to get a "good enough" update frequency that doesn't tax the phone as much.

If GPS cannot fetch location, switch to network in Android

I am trying to get location based on GPS or network but the problem is that if I take based on GPS location it takes lot of time to fetch the location details. Hence I would like implement a method where if GPS signal is very low fetch location using network provider. How do I determine the GPS signal? if do there is problem with this? GPS signal is always low even in open sky and hence it would always get to network provider?
How do I fix this problem?
Are you polling the location with LocationManager.GetLastKnownLocation, or are you getting updates asynchronously via requestLocationUpdates?
For the first, query for the location with the GPS_PROVIDER. If it returns null, then query for NETWORK_PROVIDER
If you're getting notifications, request both. Then you can implement onStatusChanged to tell when the GPS is available or not, and ignore network updates if it is, or use them if not (the location object tells you what the provider was).
Adding lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll); it will start fetching the gps using networ. Using location.getProvider() you should be able to differentiate to know whether its gps or network.

Categories

Resources