location.getAccuracy()的奇怪和非常意外的问题

时间:2018-03-12 15:14:09

标签: android android-location fusedlocationproviderapi fusedlocationproviderclient

问题:

我尝试使用新的FusedLocationProviderClient和已弃用的FusedLocationApi使用 Sony Xperia Z2 Huawei Honor 8 接收我的应用上的位置更新。一切都很好。但是,似乎在x位置请求后,使用location.getAccuracy(); // 10.0

的精确度数从不降至10.0以下

我尝试了什么:

卸载并重新安装应用程序没有任何区别。重启手机,结果相同。是的我有LocationRequest.PRIORITY_HIGH_ACCURACY ......没有不同的结果。

可行的方法:

工厂重置了吗? Whooppaa突然我现在得到的数字低于10.0,正如预期的那样,外面有明显的条件。但为什么??

问题:

我怀疑系统在x位置更新后限制了我的准确性(为了节省电池???)......你们怎么想?这可能是什么问题?

修改

在手机上进行软件重置后,我再次获得低于10的准确度数字。但是,在x个位置更新后,精度数量再次限制在10.0米。我应该说我的GPS设计为一次可以运行前景长达3.5小时。是的,我知道这是电池耗尽。

public class GPSServiceNew extends Service{

    private FusedLocationProviderClient mFusedLocationClient;
    private LocationRequest mLocationRequest;
    private long UPDATE_INTERVAL = 10 * 1000;  /* 10 secs */
    private long FASTEST_INTERVAL = 2000; /* 2 sec */


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        String test = "";

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        mFusedLocationClient = getFusedLocationProviderClient(this);
        startLocationUpdates();

        Intent notificationIntent = new Intent(this, MainActivity.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, 0);

        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setContentTitle("My Awesome App")
                .setContentText("Doing some work...")
                .setContentIntent(pendingIntent).build();

        startForeground(100, notification);

    }

    // Trigger new location updates at interval
    @SuppressLint("MissingPermission")
    protected void startLocationUpdates() {

        // Create the location request to start receiving updates
        mLocationRequest = new LocationRequest();
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationRequest.setInterval(UPDATE_INTERVAL);
        mLocationRequest.setFastestInterval(FASTEST_INTERVAL);

        // Create LocationSettingsRequest object using location request
        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
        builder.addLocationRequest(mLocationRequest);
        LocationSettingsRequest locationSettingsRequest = builder.build();

        // Check whether location settings are satisfied
        // https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient
        SettingsClient settingsClient = LocationServices.getSettingsClient(this);
        settingsClient.checkLocationSettings(locationSettingsRequest);

        // new Google API SDK v11 uses getFusedLocationProviderClient(this)
        getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest, new LocationCallback() {
                    @Override
                    public void onLocationResult(LocationResult locationResult) {
                        // do work here
                        onLocationChanged(locationResult.getLastLocation());
                    }
                },
                Looper.myLooper());
    }

    public void onLocationChanged(Location location) {
        // New location has now been determined
        String msg = "Updated Location: " +
                String.valueOf(location.getAccuracy());
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        // You can now create a LatLng Object for use with maps
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

        Log.d("GPS: ", String.valueOf(location.getAccuracy()));
    }

}

0 个答案:

没有答案