我写了一个GPSTracker类,其中包含位置更新,
一切正常,但看起来只有在GPS状态发生变化时才会调用onLocationChanged
。我想获取位置,即使它来自网络。
这是我的请求代码,我也尝试了PRIORITY_HIGH_ACCURACY
:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
sharedPref = getSharedPreferences(getString(R.string.preference_details_key), Context.MODE_PRIVATE);
//building googleapiclient
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
connect();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
disConnect();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(3600000);
mLocationRequest.setFastestInterval(60000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
}