简体   繁体   English

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

[英]Obtain GPS or Network provider from Fused Location Provider

I'm using a location service in the background using Fused Location Provider, it returns "fused" when I call the method getProvider() instead of Network or GPS.我正在使用 Fused Location Provider 在后台使用定位服务,当我调用方法 getProvider() 而不是 Network 或 GPS 时,它会返回“fused”。 Is there a way I can get the provider from this?有没有办法让我从中获得提供者?

I know that using LocationManager with GPS location I can get GPS or Network, but the listener gets killed when I try to use it in a background service.我知道将 LocationManager 与 GPS 位置一起使用,我可以获得 GPS 或网络,但是当我尝试在后台服务中使用它时,监听器会被杀死。

Here is part of my code inside the onCreate method这是我在 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?有没有办法让我从中获得提供者?

You are.你是。 It is the fused provider.它是融合的提供者。 The locations provided by the fused provider are computed based not only on the GPS and network providers but other data sources as well, using proprietary algorithms.融合提供商提供的位置不仅基于 GPS 和网络提供商,而且还使用专有算法基于其他数据源进行计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM