2

I am working on googlemaps application,i am using google fusion location provider for finding currentlocation and i am trying requestlocationupdates but the problem i am facing when i am using gps and locationrequest priority HIGH_ACCURACY,my battery is getting drain very fast thats why i wanted to change my locationrequest priority to BALANCED_POWER but without gps i am unable to get latitude and longitude but in google docs they mentioned without gps also it should work please reply

code:

_googleApiClient = new GoogleApiClient.Builder(this)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
 _locationRequest = new LocationRequest();
 _locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
  PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(
                    _googleApiClient, _locationRequest,this);
skyshine
  • 2,767
  • 7
  • 44
  • 84
  • could you manage to achieve what you wanted ? I was curious if it did work for you.. – cgr Nov 25 '15 at 21:51

1 Answers1

1

PRIORITY_BALANCED_POWER_ACCURACY gets only the network based locations as per the google doc. It needs only ACCESS_COARSE_LOCATION which means it gets the locations based only on Network but not GPS. Take a look a this post.

You should go for HIGH_ACCURACY locations if you want to use GPS. As your requirement if for maps, it makes sense to go for it. You should not forget removing the locations update when you don’t need. In your case, I guess you should stop when your activity goes background..may be in onStop() or onPause(). Read Location Strategies for more info.

Community
  • 1
  • 1
cgr
  • 4,578
  • 2
  • 28
  • 52
  • but i need to track location of person for every 15 min using high_accuracy battery drain is happening so i am thinking to use balance_power_accuracy but i am not getting location in google map if i switch off gps – skyshine Nov 26 '15 at 04:19
  • Even if you keep the gps ON, I think (I am mostly sure after reading doc) you wont receive any locations. So you either have to go for HIGH_ACCURACY with less freuqent or go with BALANCED for less accurate. Or else you can combine both - in foreground you can prepare LocationRequest with HIGH_ACC and when app goes background, you can prepare new LocationRequest with BALANCED. If it is 15 min once, I don't think it drains the batttery so much. Did you do the power test to know how much your app is consuming with HIGH_ACCURACY and 15 min frequency. ??? – cgr Nov 26 '15 at 10:00
  • Good it helped you. You may vote up so others can have confidence to consider the answer for their work too. – cgr Nov 28 '15 at 08:30
  • if i change dynamically location request priority to BALANCED will it work or should i change it manually by going location settings – skyshine Dec 03 '15 at 07:46
  • Liason settings should be enabled. .gps should be enabled for high_accuracy and WiFi for balanced. Keep both on til it work then you can experiment. Create new request and requestLocationUpdates() – cgr Dec 03 '15 at 08:26