Soufyane Kaddouri
Soufyane Kaddouri

Reputation: 333

What is the new getMyLocation function instead of the deprecated one? (Android Java)

I have a google maps activity and i want to get the location of the user, but the function i want to use: getMyLocation() is deprecated.

Here is my piece of code:

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    // This function is deprecated
    // What is the new function?
    mMap.getMyLocation();

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

Upvotes: 9

Views: 12473

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007534

Quoting the documentation:

use com.google.android.gms.location.FusedLocationProviderApi instead. FusedLocationProviderApi provides improved location finding and power usage and is used by the "My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder for example example code, or the Location Developer Guide.

IOW, there is no replacement method. Instead, you use other APIs for finding the user's location.

Upvotes: 9

Related Questions