1

问题:


我已经尝试使用新FusedLocationProviderClient的和已弃用FusedLocationApi的在我的应用程序上使用Sony Xperia Z2Huawei Honor 8接收位置更新。最初一切正常。然而,似乎在 x 数量的位置请求之后,准确 度数永远不会低于 10.0 使用location.getAccuracy(); // 10.0

我试过的:


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

什么可能有效:


有没有恢复出厂设置。Whooppaa 突然间,我现在得到的数字低于 10.0,正如预期的那样,外面的情况很清楚。但为什么??

问题:


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

编辑:


在手机上进行软件重置后,我的准确度数字再次低于 10。但是在 x 次位置更新后,准确度数再次限制为 10.0m。我应该说我的 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()));
    }

}
4

0 回答 0