sunil paudel
sunil paudel

Reputation: 31

map.setMyLocationEnabled(true); is not working

I have just started working on a android project and is using the Google Map API.

I am able to fetch the map on my app but when i try to enable the current location with map.setMyLocationEnabled(true);, the app says unfortunately app has stopped working.

When I removed the line map.setMyLocationEnabled(true); then it worked fine. Can anyone please help me to get the current location button enabled.

Upvotes: 2

Views: 4119

Answers (2)

Kingfisher Phuoc
Kingfisher Phuoc

Reputation: 8200

If you are using android 6.0 or above, you should:

  1. Make sure you added ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION in your AndroidManifest file.
  2. You need to check permission at run-time in this link: Requesting Permission

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality;

If you want an easy-to-use library for permission checking, I suggest Permission Dispatcher.

Upvotes: 1

Tyler Sebastian
Tyler Sebastian

Reputation: 9458

According to this, you need to have requested permission for either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION.

My guess is you haven't and your app is throwing a SecurityException.

Upvotes: 0

Related Questions