Show Current Location in a Google Map for Android

Here is a full Activity class that places a Marker at the current location, and also moves the camera to the current position.
There are a few things going on in sequence here:

  • Check Location permission
  • Once Location permission is granted, call setMyLocationEnabled(), build the GoogleApiClient, and connect it
  • Once the GoogleApiClient is connected, request location updates



Show explanation if needed on Marshmallow and Nougat using an AlertDialog (this case happens when the user had previously denied a permission request, or had granted the permission and then later revoked it in the settings):

Prompt the user for Location permission on Marshmallow and Nougat by calling ActivityCompat.requestPermissions():

Move camera to current location and place Marker when the Location permission is granted:

Leave a Reply

Your email address will not be published. Required fields are marked *

9 + twelve =

Comment moderation is enabled. Your comment may take some time to appear.