I searched everywhere on the Internet for a good tutorial that explains how to get the user's location on the MapsActivity (Android Studio). But I didn't find, even some explanations in a forum.
So here's what I want: When the user goes on the Map layout of my app, they should see their current location.
I created the MapsActivity (from Android Studio) and put the right permissions on my Manifest. But I do not know what function to use to get the current user's location and where to put that function?
Below is the code of the MapsActivity:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Paris and move the camera
LatLng paris = new LatLng(48.858930, 2.350831);
mMap.addMarker(new MarkerOptions().position(paris).title("Marker in Paris"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(paris));
}
}
Thank you very much!