Java 如何使用FusedLocationProviderClient获取Google地图中的当前位置

Java 如何使用FusedLocationProviderClient获取Google地图中的当前位置,java,android,google-maps-android-api-2,android-fusedlocation,Java,Android,Google Maps Android Api 2,Android Fusedlocation,我想为此定期(比如每2分钟)获取当前位置更新我遵循官方文档,我编写了这段代码,但它没有每两分钟提供当前位置更新,即使是在我传入RequestLocationUpdate()的LocationRequest对象中指定的,下面是代码: public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiCl

我想为此定期(比如每2分钟)获取当前位置更新我遵循官方文档,我编写了这段代码,但它没有每两分钟提供当前位置更新,即使是在我传入RequestLocationUpdate()的LocationRequest对象中指定的,下面是代码:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
    GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{

private FusedLocationProviderClient FusedLocationClient;
private GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }

 SupportMapFragment map = 
  getSupportFragmentManager().findFragmentById(R.id.map));

  map.getMapAsync(this);

  FusedLocationClient LocationServices.getFusedLocationProviderClient(this);
}


@Override
public void onConnected(Bundle bundle) {
    FusedLocationClient.getLastLocation()
            .addOnSuccessListener(this, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {

                    if (location != null) {
                        Log.i("MainActivity ", "" + location.getLongitude()) 
                    }
                }
            });
FusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
FusedLocationClient.requestLocationUpdates(requestLocation(), 
new LocationCallback(){
        @Override
        public void onLocationResult(LocationResult locationResult) {
            for (Location location : locationResult.getLocations()) {
               Log.i("MainActivity ", "" + location.getLongitude());
               //not getting current location updates every 2 minutes
            }
        };

    },null);

}

@Override
public void onConnectionSuspended(int i) {}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {}
公共类MapsActivity扩展了FragmentActivity在MapreadyCallback上的实现,
GoogleAppClient.ConnectionCallbacks,GoogleAppClient.OnConnectionFailedListener{
私有FusedLocationProviderClient FusedLocationClient;
私人GoogleapClient MGoogleapClient;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
if(mGoogleApiClient==null){
mgoogleapclient=新的Googleapclient.Builder(此)
.addConnectionCallbacks(此)
.addOnConnectionFailedListener(此)
.addApi(LocationServices.API)
.build();
}
SupportMapFragment映射=
getSupportFragmentManager().findFragmentById(R.id.map));
getMapAsync(this);
FusedLocationClient LocationServices.getFusedLocationProviderClient(此);
}
@凌驾
未连接的公共空间(捆绑包){
FusedLocationClient.getLastLocation()文件
.addOnSuccessListener(此,新的OnSuccessListener(){
@凌驾
成功时的公共无效(位置){
如果(位置!=null){
Log.i(“MainActivity”,“”+location.getLongitude())
}
}
});
FusedLocationClient=LocationServices.getFusedLocationProviderClient(此);
FusedLocationClient.RequestLocationUpdate(requestLocation(),
新位置回调(){
@凌驾
public void onLocationResult(LocationResult LocationResult){
对于(位置:locationResult.getLocations()){
Log.i(“MainActivity”,“location.getLength());
//未每2分钟获取当前位置更新
}
};
},空);
}
@凌驾
连接已暂停(int i){}
@凌驾
连接失败(ConnectionResult ConnectionResult){}
实现位置更改侦听器,您将能够覆盖onlocation changed…

这与我的类似,已更新为使用最近引入的类

要将FusedLocationProviderClient与Google地图结合使用,请执行以下操作:

  • 等待谷歌地图准备就绪

  • 如果需要,请在运行时请求位置权限

  • 授予权限后,请求位置将更新

  • 获取用户位置后,更新谷歌地图

  • 首先确保您使用的Google Play服务至少是版本11,因为旧版本没有FusedLocationProviderClient类(新版本也可以):

    请注意,FusedLocationProviderClient在11.0.2版中存在,但由于初始实现中存在错误,建议您仅在11.6.0及更高版本中使用此类。 从文件中:

    注意:建议使用Google Play services 11.6.0或更高版本 更高版本,包括此类的错误修复

    在AndroidManifest.xml文件中,在
    manifest
    标记内部和
    应用程序
    标记外部添加位置权限:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    
        <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="AIza___YOUR_KEY_HERE______"/>
    
    Kotlin

    以下是Kotlin的完整活动课程:

    class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
    
        lateinit var mGoogleMap: GoogleMap
        var mapFrag: SupportMapFragment? = null
        lateinit var mLocationRequest: LocationRequest
        var mLastLocation: Location? = null
        internal var mCurrLocationMarker: Marker? = null
        internal var mFusedLocationClient: FusedLocationProviderClient? = null
    
        internal var mLocationCallback: LocationCallback = object : LocationCallback() {
            override fun onLocationResult(locationResult: LocationResult) {
                val locationList = locationResult.locations
                if (locationList.isNotEmpty()) {
                    //The last location in the list is the newest
                    val location = locationList.last()
                    Log.i("MapsActivity", "Location: " + location.getLatitude() + " " + location.getLongitude())
                    mLastLocation = location
                    if (mCurrLocationMarker != null) {
                        mCurrLocationMarker?.remove()
                    }
    
                    //Place current location marker
                    val latLng = LatLng(location.latitude, location.longitude)
                    val markerOptions = MarkerOptions()
                    markerOptions.position(latLng)
                    markerOptions.title("Current Position")
                    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA))
                    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions)
    
                    //move map camera
                    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 11.0F))
                }
            }
        }
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_maps)
    
            supportActionBar?.title = "Map Location Activity"
    
            mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
    
            mapFrag = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
            mapFrag?.getMapAsync(this)
        }
    
        public override fun onPause() {
            super.onPause()
    
            //stop location updates when Activity is no longer active
            mFusedLocationClient?.removeLocationUpdates(mLocationCallback)
        }
    
        override fun onMapReady(googleMap: GoogleMap) {
            mGoogleMap = googleMap
            mGoogleMap.mapType = GoogleMap.MAP_TYPE_HYBRID
    
            mLocationRequest = LocationRequest()
            mLocationRequest.interval = 120000 // two minute interval
            mLocationRequest.fastestInterval = 120000
            mLocationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (ContextCompat.checkSelfPermission(
                        this,
                        Manifest.permission.ACCESS_FINE_LOCATION
                    ) == PackageManager.PERMISSION_GRANTED
                ) {
                    //Location Permission already granted
                    mFusedLocationClient?.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
                    mGoogleMap.isMyLocationEnabled = true
                } else {
                    //Request Location Permission
                    checkLocationPermission()
                }
            } else {
                mFusedLocationClient?.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
                mGoogleMap.isMyLocationEnabled = true
            }
        }
    
        private fun checkLocationPermission() {
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.ACCESS_FINE_LOCATION
                ) != PackageManager.PERMISSION_GRANTED
            ) {
                // Should we show an explanation?
                if (ActivityCompat.shouldShowRequestPermissionRationale(
                        this,
                        Manifest.permission.ACCESS_FINE_LOCATION
                    )
                ) {
                    // Show an explanation to the user *asynchronously* -- don't block
                    // this thread waiting for the user's response! After the user
                    // sees the explanation, try again to request the permission.
                    AlertDialog.Builder(this)
                        .setTitle("Location Permission Needed")
                        .setMessage("This app needs the Location permission, please accept to use location functionality")
                        .setPositiveButton(
                            "OK"
                        ) { _, _ ->
                            //Prompt the user once explanation has been shown
                            ActivityCompat.requestPermissions(
                                this@MapsActivity,
                                arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                                MY_PERMISSIONS_REQUEST_LOCATION
                            )
                        }
                        .create()
                        .show()
    
    
                } else {
                    // No explanation needed, we can request the permission.
                    ActivityCompat.requestPermissions(
                        this,
                        arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                        MY_PERMISSIONS_REQUEST_LOCATION
                    )
                }
            }
        }
    
        override fun onRequestPermissionsResult(
            requestCode: Int,
            permissions: Array<String>, grantResults: IntArray
        ) {
            when (requestCode) {
                MY_PERMISSIONS_REQUEST_LOCATION -> {
                    // If request is cancelled, the result arrays are empty.
                    if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    
                        // permission was granted, yay! Do the
                        // location-related task you need to do.
                        if (ContextCompat.checkSelfPermission(
                                this,
                                Manifest.permission.ACCESS_FINE_LOCATION
                            ) == PackageManager.PERMISSION_GRANTED
                        ) {
    
                            mFusedLocationClient?.requestLocationUpdates(
                                mLocationRequest,
                                mLocationCallback,
                                Looper.myLooper()
                            )
                            mGoogleMap.setMyLocationEnabled(true)
                        }
    
                    } else {
    
                        // permission denied, boo! Disable the
                        // functionality that depends on this permission.
                        Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show()
                    }
                    return
                }
            }// other 'case' lines to check for other
            // permissions this app might request
        }
    
        companion object {
            val MY_PERMISSIONS_REQUEST_LOCATION = 99
        }
    }
    

    这对我来说很有用。

    要使其简单,请尝试使用此库。这将使用融合位置提供程序

    你只要把这个密码

    SmartLocation.with(context).location(new LocationBasedOnActivityProvider(callback))
        .start(new OnLocationUpdatedListener() { ... });
    

    谢谢,如果我们想每移动10步就获取设备的当前位置,比如我们正在移动并实时获取当前位置更新,那么坐标也会有轻微变化,比如首先我得到了25.3767231,然后是25.3756256,即使在获得2次更新后设备位置没有变化,延迟也会增加increasing@blackHawk对于在第一条注释中,您可以设置一个较小的时间间隔,并对LocationRequest使用
    setSmallestDisplacement()
    方法:“mLocationCallback”是什么?我在变量中找不到它-box@DanielNugent很好的回答和解释
    class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
    
        lateinit var mGoogleMap: GoogleMap
        var mapFrag: SupportMapFragment? = null
        lateinit var mLocationRequest: LocationRequest
        var mLastLocation: Location? = null
        internal var mCurrLocationMarker: Marker? = null
        internal var mFusedLocationClient: FusedLocationProviderClient? = null
    
        internal var mLocationCallback: LocationCallback = object : LocationCallback() {
            override fun onLocationResult(locationResult: LocationResult) {
                val locationList = locationResult.locations
                if (locationList.isNotEmpty()) {
                    //The last location in the list is the newest
                    val location = locationList.last()
                    Log.i("MapsActivity", "Location: " + location.getLatitude() + " " + location.getLongitude())
                    mLastLocation = location
                    if (mCurrLocationMarker != null) {
                        mCurrLocationMarker?.remove()
                    }
    
                    //Place current location marker
                    val latLng = LatLng(location.latitude, location.longitude)
                    val markerOptions = MarkerOptions()
                    markerOptions.position(latLng)
                    markerOptions.title("Current Position")
                    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA))
                    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions)
    
                    //move map camera
                    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 11.0F))
                }
            }
        }
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_maps)
    
            supportActionBar?.title = "Map Location Activity"
    
            mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
    
            mapFrag = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
            mapFrag?.getMapAsync(this)
        }
    
        public override fun onPause() {
            super.onPause()
    
            //stop location updates when Activity is no longer active
            mFusedLocationClient?.removeLocationUpdates(mLocationCallback)
        }
    
        override fun onMapReady(googleMap: GoogleMap) {
            mGoogleMap = googleMap
            mGoogleMap.mapType = GoogleMap.MAP_TYPE_HYBRID
    
            mLocationRequest = LocationRequest()
            mLocationRequest.interval = 120000 // two minute interval
            mLocationRequest.fastestInterval = 120000
            mLocationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (ContextCompat.checkSelfPermission(
                        this,
                        Manifest.permission.ACCESS_FINE_LOCATION
                    ) == PackageManager.PERMISSION_GRANTED
                ) {
                    //Location Permission already granted
                    mFusedLocationClient?.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
                    mGoogleMap.isMyLocationEnabled = true
                } else {
                    //Request Location Permission
                    checkLocationPermission()
                }
            } else {
                mFusedLocationClient?.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
                mGoogleMap.isMyLocationEnabled = true
            }
        }
    
        private fun checkLocationPermission() {
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.ACCESS_FINE_LOCATION
                ) != PackageManager.PERMISSION_GRANTED
            ) {
                // Should we show an explanation?
                if (ActivityCompat.shouldShowRequestPermissionRationale(
                        this,
                        Manifest.permission.ACCESS_FINE_LOCATION
                    )
                ) {
                    // Show an explanation to the user *asynchronously* -- don't block
                    // this thread waiting for the user's response! After the user
                    // sees the explanation, try again to request the permission.
                    AlertDialog.Builder(this)
                        .setTitle("Location Permission Needed")
                        .setMessage("This app needs the Location permission, please accept to use location functionality")
                        .setPositiveButton(
                            "OK"
                        ) { _, _ ->
                            //Prompt the user once explanation has been shown
                            ActivityCompat.requestPermissions(
                                this@MapsActivity,
                                arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                                MY_PERMISSIONS_REQUEST_LOCATION
                            )
                        }
                        .create()
                        .show()
    
    
                } else {
                    // No explanation needed, we can request the permission.
                    ActivityCompat.requestPermissions(
                        this,
                        arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                        MY_PERMISSIONS_REQUEST_LOCATION
                    )
                }
            }
        }
    
        override fun onRequestPermissionsResult(
            requestCode: Int,
            permissions: Array<String>, grantResults: IntArray
        ) {
            when (requestCode) {
                MY_PERMISSIONS_REQUEST_LOCATION -> {
                    // If request is cancelled, the result arrays are empty.
                    if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    
                        // permission was granted, yay! Do the
                        // location-related task you need to do.
                        if (ContextCompat.checkSelfPermission(
                                this,
                                Manifest.permission.ACCESS_FINE_LOCATION
                            ) == PackageManager.PERMISSION_GRANTED
                        ) {
    
                            mFusedLocationClient?.requestLocationUpdates(
                                mLocationRequest,
                                mLocationCallback,
                                Looper.myLooper()
                            )
                            mGoogleMap.setMyLocationEnabled(true)
                        }
    
                    } else {
    
                        // permission denied, boo! Disable the
                        // functionality that depends on this permission.
                        Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show()
                    }
                    return
                }
            }// other 'case' lines to check for other
            // permissions this app might request
        }
    
        companion object {
            val MY_PERMISSIONS_REQUEST_LOCATION = 99
        }
    }
    
    public class MapsActivity extends AppCompatActivity
            implements OnMapReadyCallback {
    
        GoogleMap mGoogleMap;
        SupportMapFragment mapFrag;
        LocationRequest mLocationRequest;
        Location mLastLocation;
        Marker mCurrLocationMarker;
        FusedLocationProviderClient mFusedLocationClient;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_maps);
    
            getSupportActionBar().setTitle("Map Location Activity");
    
            mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    
            mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            mapFrag.getMapAsync(this);
        }
    
        @Override
        public void onPause() {
            super.onPause();
    
            //stop location updates when Activity is no longer active
            if (mFusedLocationClient != null) {
                mFusedLocationClient.removeLocationUpdates(mLocationCallback);
            }
        }
    
        @Override
        public void onMapReady(GoogleMap googleMap) {
            mGoogleMap = googleMap;
            mGoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    
            mLocationRequest = new LocationRequest();
            mLocationRequest.setInterval(120000); // two minute interval
            mLocationRequest.setFastestInterval(120000);
            mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.ACCESS_FINE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED) {
                    //Location Permission already granted
                    mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
                    mGoogleMap.setMyLocationEnabled(true);
                } else {
                    //Request Location Permission
                    checkLocationPermission();
                }
            }
            else {
                mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
                mGoogleMap.setMyLocationEnabled(true);
            }
        }
    
        LocationCallback mLocationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                List<Location> locationList = locationResult.getLocations();
                if (locationList.size() > 0) {
                    //The last location in the list is the newest
                    Location location = locationList.get(locationList.size() - 1);
                    Log.i("MapsActivity", "Location: " + location.getLatitude() + " " + location.getLongitude());
                    mLastLocation = location;
                    if (mCurrLocationMarker != null) {
                        mCurrLocationMarker.remove();
                    }
    
                    //Place current location marker
                    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
                    MarkerOptions markerOptions = new MarkerOptions();
                    markerOptions.position(latLng);
                    markerOptions.title("Current Position");
                    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
                    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
    
                    //move map camera
                    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 11));
                }
            }
        };
    
        public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
        private void checkLocationPermission() {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED) {
    
                // Should we show an explanation?
                if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                        Manifest.permission.ACCESS_FINE_LOCATION)) {
    
                    // Show an explanation to the user *asynchronously* -- don't block
                    // this thread waiting for the user's response! After the user
                    // sees the explanation, try again to request the permission.
                    new AlertDialog.Builder(this)
                            .setTitle("Location Permission Needed")
                            .setMessage("This app needs the Location permission, please accept to use location functionality")
                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    //Prompt the user once explanation has been shown
                                    ActivityCompat.requestPermissions(MapsActivity.this,
                                            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                            MY_PERMISSIONS_REQUEST_LOCATION );
                                }
                            })
                            .create()
                            .show();
    
    
                } else {
                    // No explanation needed, we can request the permission.
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                            MY_PERMISSIONS_REQUEST_LOCATION );
                }
            }
        }
    
        @Override
        public void onRequestPermissionsResult(int requestCode,
                                               String permissions[], int[] grantResults) {
            switch (requestCode) {
                case MY_PERMISSIONS_REQUEST_LOCATION: {
                    // If request is cancelled, the result arrays are empty.
                    if (grantResults.length > 0
                            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    
                        // permission was granted, yay! Do the
                        // location-related task you need to do.
                        if (ContextCompat.checkSelfPermission(this,
                                Manifest.permission.ACCESS_FINE_LOCATION)
                                == PackageManager.PERMISSION_GRANTED) {
    
                            mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
                            mGoogleMap.setMyLocationEnabled(true);
                        }
    
                    } else {
    
                        // permission denied, boo! Disable the
                        // functionality that depends on this permission.
                        Toast.makeText(this, "permission denied", Toast.LENGTH_LONG).show();
                    }
                    return;
                }
    
                // other 'case' lines to check for other
                // permissions this app might request
            }
        }
    }
    
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".map.MapsActivity">
    
        <fragment android:id="@+id/map"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  tools:context=".map.MapsActivity"
                  app:layout_constraintTop_toTopOf="parent"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintBottom_toBottomOf="parent"
                  app:layout_constraintEnd_toEndOf="parent"
                  android:name="com.google.android.gms.maps.SupportMapFragment"/>
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    android.useAndroidX=true
    android.enableJetifier=true
    
     mLocationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                super.onLocationResult(locationResult);
                currentLocation = locationResult.getLastLocation();
    
            }
        };
    
    SmartLocation.with(context).location(new LocationBasedOnActivityProvider(callback))
        .start(new OnLocationUpdatedListener() { ... });