Location Request on Android Google Map, setIntervals() and if it costs anything - android

mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Setting this to 1000 ms, requests location every second and accumulates to thousands of requests in a day if app is used continuously. Will this cost me and will making less location requests than this cost me less?
I am working on an app which requires to get the drivers location. I would just like to clarify if setting shorter location request interval will cost me anything. The links given below did help but did not answer what I was actually looking for.
The second link on the costs stated on Google developers site talks about Places API and its costs. What I exactly want to know on point is that does Google charge anything on location request and its intervals?
Android Google Services Location costs and limitations
https://developers.google.com/places/android/usage
What I actually want to achieve is to move my marker on the map in real-time. I can do this by setting intervals which works as delays. I had read somewhere that moving the marker in real-time might cost me. Can I get clarification on this...
Thank you

Related

Google Place SDK gives wrong current place detail

In my application, I have a requirement where I need to track the user's current place and notify the user if he/she stays for some time.
So to do this, I am using Google's place SDK to get current place detail, reference link
But the problem is output.
If I use Location service with priority PRIORITY_HIGH_ACCURACY or PRIORITY_BALANCED_POWER_ACCURACY, the output of Place SDK is different for the same location.
My Location Request is as below:
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// or
// mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
As mentioned in above link, we don't have any option to pass current latitude-longitude, as SDK itself manage it.
So can anyone help me how I can get much accurate output from Place SDK.
Sample code of background service
as the documentation states, you probably should migrate to GoogleApi Client
while the two different results returned, should have a different PlaceLikelihood.
as a matter of fact, the less precise the requested location is, the less accure the returned places are.
for the LocationRequest, there isn't even a PRIORITY_BALANCED, but only a PRIORITY_BALANCED_POWER_ACCURACY constant available - and the request interval will be automatically throttled when this is set, no matter what you try to set as the interval.
also see the FusedLocationProviderClient.

Getting user location with minimal impact for battery on Android

I'm starting to develop an app that will stay in background forever and detect when a user is staying in a certain location for a while (and then display a notification to invite the user to open the app to obtain informations about that place).
It's something very similar to what Google Maps does when you're in a restaurant and it shows you a notification to check ratings about it.
What I want is to have a minimal impact on device, so location updates should be very "passive", getting the location only when user is not moving and, if possible, recycling location data that is already got by other activities - maybe by Google Maps itself or other location apps that are running on the devices.
This is not a navigation app, so I don't need to have the live fine location but simply the approximate place with the best accuracy and minimal effort, and only if user is not moving.
LocationListener and onLocationChanged seems to be my men, but can I specify that I don't want to trigger device's sensors and only re-use location data when it's available for other scopes? My app should check these informations and then decide to do a reverse geocode if and when they are accurate enough.
Yes, LocationListener and onLocationChanged are your men, though for a passive implementation, there are a few options you can go through.
First you can check for the last known location, maybe compare it in terms of its time; i.e. getTime() and verify whether it is of use to you.
In terms of code, literally...
Google samples, android location has what is relevant for the last location part:
/**
* Runs when a GoogleApiClient object successfully connects.
*/
#Override
public void onConnected(Bundle connectionHint) {
// Provides a simple way of getting a device's location and is well suited for
// applications that do not require a fine-grained location and that do not need location
// updates. Gets the best and most recent location currently available, which may be null
// in rare cases when a location is not available.
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Further, you can combine it with LocationRequest object, this helps your implementation as you can call it right after trying getLastLocation() and basically have a more reliable arrangement for obtaining location.
// Create the location request
mLocationRequest = LocationRequest.create()
//priority object needs to be set, the following will definitely get results for you
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
//interval updates can be on the lines of 15mins or 30... acc to your requirement
.setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL);
// Request location updates
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, this);
i suggest give PRIORITY_NO_POWER a try, could work well in combination with getLastLocation(). These power modes have been added specifically for optimising battery/power consumption and efficiency for retrieving location.

Is Update Interval Accurate for Location Updates?

I am currently trying to work with Google Play Location Updates for an Android project.
I have set the updateInterval for LocationRequests at 5000 (5 seconds) and fastestInvertval also at 5000:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setFastestInterval(5000);
I am now thinking of getting rid of old code that dealt with time-stamps and calculating speed through getting the difference between the two times. I've been hesitant to do so because I though that maybe the updateInterval for the LocationRequests would be inaccurate, and would have large margins of error.
My question is:
Is LocationRequests' Update Interval accurate so that I could remove safeguards such as the time stamps? If so, what is the approximate margin of error?
No. The updateInterval is the fastest it will return a new value. It could be close. It could take twice that. It could take 100 times that. It could take 8 hours, if someone went inside. Also very few GPS chips are going to give a new result more than once every 30 seconds, at least as of the last time I checked. In short, use timestamps.
The location updates may be faster than this rate if another app is receiving updates at a faster rate, or slower than this rate, or there may be no updates at all (if the device has no connectivity, for example)(source).
It all depends on the level of accuracy that you need, some samples might come several seconds late. You would have to see if for your application this is acceptable or not. You can always retrieve the timestamp of your location sample from the location.getTime() method if you need to check.

What happened to LocationManager and Location services? [duplicate]

Creating and Monitoring Geofences example app on github does not work as expected, Geofences in Google Play Services don't seem to work properly.
I have read elsewhere at Stack Overflow, that Reto Meier mentioned at Google IO that the GPS will turn on only if the phone approaches the geofence to conserve battery.
Seems that it does not turn on at all.
Here is the situation:
I have an Emulator with Google APIs (same happens with real phone).
I have the above mentioned app out of the box installed and Geofence added.
I have a KML file that drives me in and out of the Geofence.
Gofence ENTER is not triggered.
Now, just to be sure that KML actually works, I open Google maps. I play KML and I can see the blue "You Are Here" dot nicely moving in and out of Geofence, and the geofences do get triggered.
While Google Maps is up and running, I see GPS indicator in status bar.
So, it seems to me that Goefence only gets triggered if the GPS is explicitly on.
Can somebody explain this please? There is a lot of questions here on Stack Overflow that deal with the same problem.
Thanks.
EDIT:
Did the field test with real phone. While Location Updates app was running and tracking me Creating and Monitoring Geofences example app was getting ENTER/EXIT events. As soon as I killed Location Updates app, the Geofences app stopped getting ENTER/EXIT events.
Seems to me like Google has optimized the power consumption for Geofences to the point of uselessness.
I found the solution. It's an abuse, but that's the only way to get Geofence useful.
All I need to do is request location updates:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, mGeofencePendingIntent);
And now we can register geofences.
Here is my understanding why the above works:
According to documentation:
"If your application wants to passively observe location updates triggered by other applications, but not consume any additional power otherwise, then use the PASSIVE_PROVIDER This provider does not actively turn on or modify active location providers"
Seems to me that added geofence is one of PASSIVE_PROVIDERS. That would explain why geofence got triggered when Google Maps was open.
Of course, we could use PRIORITY_BALANCED_POWER_ACCURACY instead of HIGH (~40m accuracy) to preserve some battery and be smart about when we put geofence on and for how long.

Android Location Client not as Accurate as Google Maps App

I want to preface this by saying that I'm in China where Google location services sometimes have issues.
I'm using the LocationClient to get user's current location.
protected void onCreate(Bundle savedInstanceState) {
...
mLocationClient = new LocationClient(this, this, this);
...
}
Very straightforward. Then in my onConnected callback, I get the location.
public void onConnected(Bundle connectionHint) {
Location location = mLocationClient.getLastLocation();
...
}
The location I get back is always the same, but it is about ~500m away from my actual location. GPS is enabled, although the icon indicating it is being used does not come on. I am also on WiFi and have 3G.
When I open the actual Google Maps app, my location is perfectly accurate (unlike the location I get in my own app). I also see the icon indicating GPS is being used.
Questions
What is the Google Map app doing differently to get a more accurate location and how do I do what they do?
If the wrong location I get back is always the same what does that mean? Without overthinking too much, it is a truth of China that foreign map data companies have coordinates the are skewed off by a factor and they have to use a specific algorithm to correct for that difference; is the Google Maps app doing that?
Thanks!
When using the method 'getLastLocation()', it offers the best last known location stored by the Location. It is also in respect to what level of permission you have given the app in the manifest file.
Try using both:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
in your manifest file and see if it improves the accuracy.
China has a special dealing with GPS data, because the government force the related map producing company to add some bias.
I'm stuck with it for a period of time.
Ad. 1 Google Maps updates location continually. Try following these inductions: http://developer.android.com/training/location/receive-location-updates.html
Ad. 2 getLastLocation probably retrieves last location stored when it is updated like in point 1. If it's not updated, you will just get the same value. Location object has time attached and you can see when it was received.
turn on the Satellite view. The normal "vector" view is obfuscated in China. For some reason, the Google Maps app doesn't have this issue.
the location returned by the GPS is correct, even in China (considering a WGS84 projection). Only the maps are not.
Other maps providers like Baidu force you to use their own custom implementation of LocationClient. This way you get locations ready to be used on their map tiles.
A late answer, but this hasn't been said:
You can set the accuracy of the locationClient, using the locationRequest.
E.g.
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationClient.requestLocationUpdates(mLocationRequest, (LocationListener) this);
You can also set the frequency of updates. If you need something highly precise, take a bunch of readings over a few seconds. Then look at the "accuracy" number on each reading. Toss out any readings whose accuracy is significantly less accurate than the others. Then average the rest...
That's a pretty basic algorithm, and i'm getting accuracy within 1-2 feet on a galaxy S5 in the US.
If you use lower accuracy, it's going to average gps data with wifi and cellular results. GPS consumes more battery, so it uses it less often on this setting. Wifi uses a physical address lookup, since its always moving me towards the public road near my house, even when I'm in the middle of it.

Categories

Resources