我正在使用 Google Play 定位服务来帮助用户沿着路径导航,但我没有从Location
我收到的对象中获取指南针方位信息onLocationChanged(Location location)
。在我的实现中,我总是得到一个错误的结果hasBearing()
并getBearing()
返回 0.0 。LocationListener
下面是我使用的去除噪声代码的代码。它显示了用于创建LocationRequest
. 代码很高兴地跳到了LocationListener
实现中,所以看起来我对系统的那一部分有一个工作架构。
public class IncrementalNavigator {
private LocationClient locationClient;
private LocationRequest locationRequest;
private float headingBearing = 0.0f;
private LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.d(TAG, "The location has changed to " + location.toString());
if (location.hasBearing()) {
// I never see this updated.
headingBearing = location.getBearing();
}
// ...
}
};
public IncrementalNavigator(LocationClient locationClient) {
this.locationRequest = LocationRequest.create();
this.locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
this.locationRequest.setInterval(5000);
this.locationRequest.setFastestInterval(1000);
this.locationClient = locationClient;
this.headingBearing = locationClient
.getLastLocation()
.getBearing();
// ...
}
public void setWalkingDirections(WalkingDirections walkingDirections) {
// ...
if (walkingDirections != null) {
// ...
this.locationClient.requestLocationUpdates(locationRequest, locationListener);
} else {
this.locationClient.removeLocationUpdates(locationListener);
}
}
// ...
}
我的 AndroidManifest.xml 声明了以下权限:
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
我在Service
带有 Android 4.3 的 Galaxy Nexus 上运行代码作为 a 的一部分。WiFi已打开,GPS已打开。我的问题是:为什么我没有收到轴承更新?