我正在尝试实现一个使用Google Map API的应用程序,但我使用的是不推荐使用的方法,这导致我的应用程序无法正常运行。不建议使用的方法是:FusedLocationAPI,有什么想法可以在这种情况下替换它? 代码:
public void onConnected(@Nullable Bundle bundle) {
locationRequest = LocationRequest.create();
locationRequest.setInterval(100);
locationRequest.setFastestInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(client, locationRequest, this);
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
lastlocation = location;
if (currentLocationMarker != null) {
currentLocationMarker.remove();
}
Log.d("lat = ", "" + latitude);
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Location");
markerOptions.snippet("My Present Location");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
currentLocationMarker = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomBy(7));
if (client != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(client, this);
}
}