I want google maps to show the location of the user centered at the map as at the image 1 And this is my Fragment Code:
public class MapFragment extends Fragmen
Try Code samples of Google.
The ApiDemos repository on GitHub includes samples that demonstrate the use of location on a map:
- MyLocationDemoActivity: Using the My Location layer, including runtime permissions
- LocationSourceDemoActivity: Using a custom LocationSource
You can use the My Location layer and the My Location button to provide your user with their current position on the map.
Note: Before enabling the My Location layer, you must ensure that you have the required runtime location permission.
Enable the My Location layer on the map as follows:
mMap.setMyLocationEnabled(true);
When the My Location layer is enabled, the My Location button appears in the top right corner of the map. When a user clicks the button, the camera centers the map on the current location of the device, if it is known. The location is indicated on the map by a small blue dot if the device is stationary, or as a chevron if the device is moving.
You can always check and compare your codes to the sample code to verify or check if your implementation is correct.
Hope this helps!