- I have an Android app that has Google Maps V2 as part of the functionality.
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 the cards to work.
- My application does not start on the map screen.
Now the question is why my phone (Galaxy Nexus, just in case) starts showing the GPS icon in the status bar immediately when the application starts, but not when I get to the map screen and start working with it? I do not need to track my location and use battery power when I'm not on the map screen.
For example, the Messenger application also uses GPS for its map, but the icon appears only when the map screen is opened, and not at the beginning of the first launching action.
Googled for several hours, but found nothing. Any help would be appreciated!
Edited by:
Class MapActivity
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() {
source share