0
我正在使用gpx文件在模擬器上測試我的應用程序。 座標變化,但方向和速度始終爲零。 我檢查了我的LocationManager設置,並且.supportsSpeed()和.supportsBearing()返回true。Android GPS方位和速度始終爲零
我的GPS代碼幾乎是一到一個與這一個http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/但是這部分是最重要的,所以我在這裏貼吧:
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
Log.d("GPS support",((Boolean)locationManager.getProvider(locationManager.GPS_PROVIDER).supportsBearing()).toString());
Log.d("GPS support",((Boolean)locationManager.getProvider(locationManager.GPS_PROVIDER).supportsSpeed()).toString());
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
我只加了這個代碼
@Override
public void onLocationChanged(Location location) {
this.location = location;
}
我在活動的onCreate方法中實例化GPSTracker對象,然後在需要的地方使用gps.getLocation()。用於測試
我。GPX文件可以在這裏找到:http://snk.to/f-cdzj45ic
你檢查了你的gpx文件嗎?它是否包含速度和方位。模擬器是否支持來自gpx的速度和方位。描述了與速度和軸承相關的模擬器中使用的gpx標籤嗎? – AlexWien