我的客户想要一个 GPS 应用程序,它会以相等的时间间隔生成所有 GPS 位置的电子表格。您可以使用微调器设置时间间隔。
现在,当位置更改使用LocationManager
经理的onLocationChanged(Location loc)
回调时,我的应用程序会获取新的 GPS 位置。
有没有办法在时间间隔而不是位置改变时获取新的 GPS 位置?
代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//if you want to lock screen for always Portrait mode
setRequestedOrientation(ActivityInfo
.SCREEN_ORIENTATION_PORTRAIT);
pb = (ProgressBar) findViewById(R.id.progressBar1);
pb.setVisibility(View.INVISIBLE);
viewLog= (TextView) findViewById(R.id.ViewLong);
viewLat= (TextView) findViewById(R.id.ViewLat);
locationMangaer = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
StartGPS();
}
void StartGPS()
{
flag = displayGpsStatus();
if (flag) {
pb.setVisibility(View.VISIBLE);
locationListener = new MyLocationListener();
locationMangaer.requestLocationUpdates(LocationManager .GPS_PROVIDER, 5000, 10,locationListener);
} else {
alertbox("Gps Status!!", "Your GPS is: OFF");
}
}
@Override
public void onClick(View v) {
}
/*----------Listener class to get coordinates ------------- */
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
String longitude = "Longitude: " +loc.getLongitude();
viewLog.setText(longitude);
String latitude = "Latitude: " +loc.getLatitude();
viewLat.setText( latitude);
pb.setVisibility(View.INVISIBLE);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider,
int status, Bundle extras) {
// TODO Auto-generated method stub
}
}