Today when i was trying my code, a few doubtful thing appeared in my mind about gps provider, gps hardware, gps icon and fine location permission.
I observed my code and gps icon on Samsung galaxy s3, Htc one m8. And gps is disabled
mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 10, 0, this, Looper.myLooper());
...
#Override
public void onLocationChanged(Location location) {
mListenerRef.get().onLocationChanged(location);
}
Galaxy s3 - Gps icon didn't appear, it didn't fire onLocationChanged method. (Thats okay)
Htc one m8 - Gps icon appeared, blinking, and fired onLocationChanged (But how ?)
At this moment questions pops up
Does ACCESS_FINE_LOCATION permission give the app override gps status on some devices?
So, could the app receive location even gps disabled ?
And then i enabled gps on galaxy s3
(First 2 minutes) Gps icon appeared(but not blinking), fired onLocationChanged method (But how ?)
(After 2 minutes) Gps icon appeared(blinking), fired onLocationChanged method
Again questions pops up
What does gps icon blinking mean ? any extracanonical meaning ?
Does the blinking mean gps hardware trying first fix ?
Or blinking means the provider firing onLocationChanged method ?
What does gps icon blinking mean?
-> Well I hope u r aware that GPS provider dosen't work under roof. So it is completely impossible to get Location update from GPS provider under roof. In such situation if user enables the GPS then the GPS blinking icon appears notifying to user that it is searching for GPS.
-> Once it finds the GPS the icon dosen't blink anymore and u'll get location updates from GPS provider.
-> A still GPS icon means Android system is ready to send location updates from GPS provider.
Htc one m8 - Gps icon appeared, blinking, and fired onLocationChanged (But how ?)
-> It sounds weird getting location updates without enabling it. I'm not sure how u confirmd that u got the Location update.
-> I'll recommend u to check if GPS provider is enabled and then request for location update.
Fine_location permission will enable user to have update from gps, wifi, network. So if gps is unavailable still onlocationChange() can be fired because a recent location may have been fetched via wifi/network.
(quote from the link: http://developer.android.com/guide/topics/location/strategies.html
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.
)
How your phone showed gps icon without gps being enabled, I doubt it is possible.
With HTC One (M7) the APP has permission to use the GPS and that makes 'GPS' fair game - ('GPS' = 'GPS Spoofer', AGPS [if permitted], an APP that uses WiFi and GPS [thus position is almost always immediately available], and, of course, the Phone's real Hardware GPS / GLONASS / Galileo / etc.).
The HTC UI has an Icon for the Application that uses the GPS (whatever the Phone thinks the Provider IS, a few APPs do check Provider; they don't accept spoofed Locations, EG: Most Subscription APPs, Google Play Store, abrev. GPS;) ).
A second Icon appears for the Hardware GPS. It flashes while it waits for enough Satellites. Indoors, without WiFi, with AGPS, I can get a lock in less than 1/2 min.
You probably want to check the Error when you get your LC Message, since if you're over 100 M off you don't really know where you are and probably don't have a valid position; pending calculations from one more (weak) Satellite may be enough to get you below 50 M Error, at which point you should start accepting the Location as valid (your APP might want to record Error with Coordinates, then Locations can be displayed with a circle representing the uncertainty).
When Developing you want to be certain to buy the most popular Phone (so you have real Hardware to test on, and support the greatest number of Customers), and to buy a FEW Phones with the Hardware that you want your Android APPs to control - in your case buy Phones with different GPS Hardware, for others they may need to buy a few Phones with different Camera Hardware (or WiFi Chip, etc.).
Between the Cell Phone Mfgs version of Android, their UI, and the manner in which their GPS Hardware operates (along with other APPs you have installed, like a Spoofer) you have a LOT of variables that your Program must juggle and many situations (Error Returns) that it must allow for to operate identically on as many Devices as possible.
Hi i am working on a real time location tracking application where i have used Fused Location provider Api. I was able to get the location updates when the device is moving. But i was also able to get the location updates even if the device is stationary on a table when i am indoor. So I have calculated the distance between the last location and the current location triggered in Onlocationchanged event and checked whether the distance is less than 30 metres, to know the device is actually moving. But sometimes the distance i get is greater than 400 metres (indoor/Device is Stationary). How Can i ignore the onlocationchange event when i am indoor? Any suggestions are appreciated.Thanks in advance.
Unfortunately I don't believe there's much you can do about it.
The reason you see those updates with great changes it's because indoors, you won't get a GPS lock, so the device is relying on cell tower and WiFi hotspot triangulation to determine your location, and something around 200m to 1km is the best you'll get with this kind of technology.
A possible attempt to hack-around it would be to:
check the source and precision of the location update
use the activity recognition API to guess if the device really moved
but both are a hack, around the technology limitation and might not be as reliable.
I implemented the new LocationClient into my app, but doing a test run I noticed the readings are incorrect.
I was driving outside without GPS. WLAN on. Thus location accuracy can only be what used to be NETWORK.
I set the LocationClient to LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; and update interval to 15 sec.
When I get the data I evaluate the Location with getAccuracy() and getTime(). Both values can not be trusted.
I get an accuracy of 25 to 50m, sometimes up to 100 meters, typical for WIFI locations. However, once I left home, the location reported (with getAccuray() < 100) had nothing much to do with my current location (actual accuracy >800m). It resembled best the cell tower location. Location was never updated in the hour I was traveling, thus always pointing to the same cell tower (incidently I always was in that area although traveling about 3 km).
Doing further tests I noticed that location and accuracy did not change for at least a minute after I turned wifi off. I was walking, so accelerator should be triggered. Again, location was way off to where I was, but accuracy still reported < 30m. After about 1-2 Minutes, the location was then reported with accuracy >800 m which was correct.
I can live with bad accuracy, but I need to know that.
Time is always updated to latest time also while the actual reading is older. This also seems a bug, someone already raised an issue at google for that.
Summarized it means I can not use that functionality. I get old readings reported as current and accuracy which does not match the reading.
Test where done on a Nexus 4. Phone was connected to an UMTS (3G) cell.
Are these known issues? Is there a way to work around it (getting the correct accuracy), or do I have to use the "old" LocationManager?
I ran into a peculiar problem today: We need the users geolocation to provide our service and it is working well so far (implementation before the recent Android Location API release, have not updated it yet). We register like this
((LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE))
.requestLocationUpdates((provider == WPS)?
LocationManager.NETWORK_PROVIDER : LocationManager.GPS_PROVIDER,
minTime, minDist, onChange(ctx, provider)); // onChange create a pending intent
and on certain events we call
Location gpsLocation = LocMngr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location wpsLocation = LocMngr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
On a HTC One S running on Android 4.0.3 and HTC Sense 4.0 we never receive location updates and the last known location returns null for gps and a 2 day old location for wps. WIFI, GPS and Mobile Data is turned on, i've tried walking around outside and saw the device trying to get a gps fix, but apparently it did not get one. Other devices have no problem with receiveing location updates from gps or wps using the same code...
This only occurs on this device (it's a test device so bootloader is locked, not rooted or any other funky stuff that might break brick it)
I am at a loss, any ideas?
UPDATE
Since we rebooted the device the problem did not occur again, I am still wondering what caused the problem...
UPDATE 2
I ran into the same Problem yesterday with a Galaxy Nexus official Android 4.2.2. So this seems to be a problem of Android in general.
Now that apparently nobody knows how to solve this, is there any way to detect when the Location API is not sending any fixes anymore? Apart from checking the timestamp of the lastKnownLocation()?
In my application i need to show Current Lcoation every 30 minutes.To implement this, I have used Timer to trigger every 30 minutes.
It's working fine in some android devices like HTC Wildfire S, Sony Xperia V...
but it's not working in Samsung S Duos and HTC One X...Because when i request GPS it returning NULL as Current Location value.I dont' know why that devices are not support my application can anyone help with profe.
You should check for provider availability like this:
List<String> providers = locationManager.getProviders(true);
and then you start listening to available sensors:
if (providers.contains(LocationManager.GPS_PROVIDER))
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,...);
}
If the sensors you want are not available you should popup a dialog to user to ask him to activate the GPS, or what you want.
Also, I have a recommendation to you: you should not start requesting location updates with Timer, you should pass to requestLocationUpdates() the minimum time & distance you want location updates.