Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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));
}
like image 941
Soufyane Kaddouri Avatar asked Jul 09 '16 22:07

Soufyane Kaddouri


1 Answers

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.

like image 178
CommonsWare Avatar answered Nov 06 '22 21:11

CommonsWare