我在android中使用FusedLocationProviderClient
类来获取用户的最后位置。一切都很好,我可以获得纬度和经度,但是 task.getResult().getBearing()
返回 0.0
和 task.getResult().hasBearing()
返回 false
。如何获取用户的方位信息?
我在 AndroidManifest 文件中和运行时都获得了 ACCESS_FINE_LOCATION
和 ACCESS_COARSE_LOCATION
权限。
这是与我正在使用的用户位置相关的代码段:
@SuppressLint("MissingPermission")
private void getLastLocation() {
fusedLocationClient
.getLastLocation()
.addOnCompleteListener(this, new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
if (task.isSuccessful() && task.getResult() != null) {
onLocationChange(task.getResult());
Log.i(TAG, "lat " + task.getResult().getLatitude() + " lng " + task.getResult().getLongitude());
Log.i(TAG, "bearing? " + task.getResult().hasBearing());
} else {
Toast.makeText(MainActivity.this, "Location Not Found!", Toast.LENGTH_SHORT).show();
}
}
});
}
private void onLocationChange(Location location) {
//do something
}
最佳答案
If this location does not have a bearing then 0.0 is returned.
关于android - FusedLocationProviderClient 没有方位数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51628283/