GPS_PROVIDER无法获取位置更新

时间:2013-04-29 18:10:53

标签: android gps

我有一个使用GPS_PROVIDER获取位置的代码。如果禁用GPS,它将使用NETWORK_PROVIDER获取位置。代码:

private static long MIN_TIME = 1 * 5 * 1000; // 5 seconds
private static final long MIN_DISTANCE = 1; // 1 meter
protected LocationManager location_manager;
protected Location location; 

public void startLocationService() {

    location_manager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
    location_manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,MIN_TIME,MIN_DISTANCE, this);
    location_manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME,MIN_DISTANCE, this);

    location = location_manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location == null) {
        location = location_manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
}

@Override
public void onLocationChanged(Location location) {
    // Updates the class's location variable
    this.location = location;
}

这几天都运行良好,但最近,我的onLocationChanged函数在过去3天内没有被调用。我真的开车绕过它以便它可以检测到我的新位置,但我在“位置”变量中得到的坐标是一个3天的缓存。

当我在Android设置中关闭GPS时,我的应用程序可以使用NETWORK_PROVIDER正确确定我的位置。但是当我重新打开GPS时,应用程序会返回我3天的缓存坐标,并且我的onLocationChanged函数永远不会被调用(即使我在外面)。

奇怪的是,无论GPS是打开还是关闭,Google地图应用都能够获得正确的坐标。

有谁知道什么可能是错的?为什么当我的应用无法使用GPS(而不是网络)时,谷歌地图可以正确地获取位置更新? Google Map应用是否会使用其他内容?

0 个答案:

没有答案