fusedlocationproviderclient.getcurrentlocation如何工作?取消令牌

72qzrwbm  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(346)

我正在尝试请求当前位置,如果任务出错,请在“位置”处于启用状态时调用。

private void getCurrentLocation() {
    fusedClient.getCurrentLocation(LocationRequest.PRIORITY_HIGH_ACCURACY, new CancellationToken() {
        @Override
        public boolean isCancellationRequested() {
            return false;
        }

        @NonNull
        @Override
        public CancellationToken onCanceledRequested(@NonNull OnTokenCanceledListener onTokenCanceledListener) {
            Log.d("CurrentLocation", "CancelRequest");
            createLocationSettingRequest();
            return null;
        }
    }).addOnSuccessListener(new OnSuccessListener<Location>() {
        @Override
        public void onSuccess(Location location) {
            if (location != null) {
                Log.d("CurrentLocation", location.toString());
                mapFragment.getMapAsync(MapsActivity.this)
            }
        }
    });
}

问题是oncancelationrequested中的代码执行了两次;我尝试了cancellationtokensource,但得到了相同的结果。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题