Reputation: 7041
Hi I implemented The google play services for location in my application(I'm using almost the same code of the sample from google). And after testing, the application doesn't seem to work as I expect.
If I set the accuracy to PRIORITY_BALANCED_POWER_ACCURACY
or PRIORITY_NO_POWER
, The Location simply doesn't fetch anything when I'm not connected to wifi.
And the amount of time the location is fetched is at minimum double than the interval that I set in mLocationRequest.setInterval()
Anybody else having this problem ? Or am I missing something here ?
Thank you.
Upvotes: 1
Views: 3192
Reputation: 7041
Ok i found the problem,
I added only the <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
but didn't add the
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
(I thought this one was only for GPS) I was wrong.
The <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
gives the precision on a city block level according to Android documentation.
Apps that use Location Services must request location permissions. Android has two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION. The permission you choose controls the accuracy of the current location. If you request only coarse location permission, Location Services obfuscates the returned location to an accuracy that's roughly equivalent to a city block.
So in my case on short distances it was always getting the same location.
Adding the <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
solved the problem.
Upvotes: 0
Reputation: 9385
Take a look at the documentation. The emphasis in bold is mine.
At the other extreme, if you want negligible power impact, but to still receive location updates when available, then create a location request with setPriority(int) set to PRIORITY_NO_POWER. With this request your application will not trigger (and therefore will not receive any power blame) any location updates, but will receive locations triggered by other applications. This would be appropriate for applications that have no firm requirement for location, but can take advantage when available.
For the second part, the PRIORITY_BALANCED_POWER_ACCURACY. That part doesn't seem to be responding as the documentation describes. I need to look more into it.
In between these two extremes is a very common use-case, where applications definitely want to receive updates at a specified interval, and can receive them faster when available, but still want a low power impact. These applications should consider PRIORITY_BALANCED_POWER_ACCURACY combined with a faster setFastestInterval(long) (such as 1 minute) and a slower setInterval(long) (such as 60 minutes). They will only be assigned power blame for the interval set by setInterval(long), but can still receive locations triggered by other applications at a rate up to setFastestInterval(long). This style of request is appropriate for many location aware applications, including background usage. Do be careful to also throttle setFastestInterval(long) if you perform heavy-weight work after receiving an update - such as using the network.
Upvotes: 4