0

Maybe look similar with many questions posted here but none of old solutions don't work anymore. I tested all and in all cases crash my application.

I need to display current user location in my MapFragment.

I try to use this code found on net:

       

LocationManager locationManager;

   

locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);

Criteria criteria = new Criteria();

   

String provider = locationManager.getBestProvider(criteria, true);

   

Location location = locationManager.getLastKnownLocation(provider);

   

locationManager.requestLocationUpdates(provider, 20000, 0, this);

       

but my application crash. He stop running before displaying anything.

The problem is here :  

    Location location = locationManager.getLastKnownLocation(provider);

        locationManager.requestLocationUpdates(provider, 20000, 0, this);

What I do wrong? This is my first android application.

  • Use LogCat to examine the Java stack trace associated with the crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Nov 21 '16 at 20:29
  • Most likely a SecurityException. If your target api is 23 or higher, you will need to do a runtime location permission check. Take a look at the linked duplicate for more details. – Daniel Nugent Nov 21 '16 at 20:44

0 Answers0