I have
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
in my manifest, and everything else needed for maps to work.
Now the question is why does my phone (Galaxy Nexus, just in case) starts showing GPS icon in status bar right when app starts, but not when I get to the screen with maps and start to work with it? I don't need to track my location and use battery power when I'm not on maps screen.
For example What's App messenger also uses GPS for its map but the icon is showed only when you open the map screen, not right on the first activity that is launched.
Googled for couple of hours but found nothing at all. Any help will be appreciated!
Edited:
MapActivity class
private LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.map_activity);
startGPS();
initMap();
mMapView = (MapView) findViewById(R.id.map_google_map);
mMapView.onCreate(null);
mGoogleMap = mMapView.getMap();
if (mGoogleMap != null) {
customizeGoogleMap();
loadAndFillMap();
}
}
private void startGPS() {
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
}
private void initMap() {
try {
MapsInitializer.initialize(this);
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
private void customizeGoogleMap() {
mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true);
mGoogleMap.setMyLocationEnabled(true);
}
private void loadAndFillMap() {
new LoadAndFillMapTask().execute();
}
private class LoadAndFillMapTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
String address = Session.appData().getSelectedAddress();
mMapLocation = Api.getMapApi().getMapLocation(address);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
fillMap();
}
}
private void fillMap() {
// filling Google Map with markers etc.
}
@Override
public void onDestroy() {
super.onDestroy();
if (mMapView != null) {
mMapView.onDestroy();
}
mLocationManager.removeUpdates(mLocationListener);
}
After a while we found out that the problem was in Flurry SDK we were using in our project...
By default Flurry starts to report location right from app start. To turn it off we used:
FlurryAgent.setReportLocation(false);
... /_-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With