永远不会调用OnLocationChanged

时间:2015-02-22 19:49:26

标签: android gps

我提供服务以获取位置更改。但即使我请求了LocationUpdates,也永远不会调用onLocationChanges(Location loc)。

public class LocationService extends Service implements LocationListener{

    ...

    @Override
    public void onProviderDisabled(String provider) {       
    }
    @Override
    public void onProviderEnabled(String provider) {    
    }   
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {   
    }

    public boolean startGPS(){
        Log.d("Debug","startGPS");
        if(gpsRunning){
            return false;
        }       
        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, this);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,this);
        Log.d("Debug","is GPS provider Enabled: "+locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
        gpsRunning=true;
        return true;
    }

    public boolean stopGPS(){
        Log.d("Debug","stopGPS");
        if(!gpsRunning){
            return false;           
        }
        locationManager.removeUpdates(this);
        gpsRunning=false;
        return true;
    }



    @Override
    public void onLocationChanged(Location location) {
        Log.d("Debug","onLocationChanged");
    }   

}

这是我的日志。你可以看到我等了32秒,什么也没发生。

02-22 20:38:59.565: D/Debug(26614): startGPS
02-22 20:38:59.590: D/Debug(26614): is GPS provider Enabled: true
02-22 20:39:31.937: D/Debug(26614): stopGPS

我在系统托盘中有图标,显示它正在尝试获取GPS位置。

1 个答案:

答案 0 :(得分:0)

我发现了一个问题。手机中的GPS无法正常工作。如果我只使用它提供的网络提供商。其他GPS应用也无法从gps获取任何位置。

相关问题