从 Fused Location Provider 获取 GPS 或网络提供商

Obtain GPS or Network provider from Fused Location Provider

我在后台使用 Fused Location Provider 定位服务,当我调用方法 getProvider() 而不是 Network 或 GPS 时,它 returns“融合”。有什么方法可以让我从中获得提供商?

我知道使用带有 GPS 位置的 LocationManager 可以获得 GPS 或网络,但是当我尝试在后台服务中使用它时监听器被杀死。

这是我在 onCreate 方法中的部分代码

locationRequest = new LocationRequest();
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(5000);
locationRequest.setSmallestDisplacement(3);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

this.locationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                super.onLocationResult(locationResult);
                Location currentLocation = locationResult.getLastLocation();
                Log.d("currentProvider", currentLocation.getProvider());
            }
        };

        this.mFusedLocationClient = LocationServices.getFusedLocationProviderClient(MyApplication.getAppContext());
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        } else {
            this.mFusedLocationClient.requestLocationUpdates(this.locationRequest,
                    this.locationCallback, Looper.myLooper());
        }

Is there a way I can get the provider from this?

你是。它是融合的提供者。融合提供商提供的位置不仅基于 GPS 和网络提供商,而且还使用专有算法计算其他数据源。