目前,我正在做的项目,以混乱的gps频率:-)。我喜欢尽快从GPS/Wifi上获取gps信息。我也想让它以尽可能高的频率工作。我的目标是从这些数据中弄乱一个频率。现在我试着这样做
final public void run() {
Looper.prepare();
while(gps){
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocationListener);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
try {
Thread.sleep(100) ;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mLocationManager.removeUpdates(mLocationListener);
}
Looper.loop();
}//run有没有更好的方法来获得更快的“采样率”?
发布于 2011-05-29 16:15:28
来自http://developer.android.com/guide/topics/location/obtaining-user-location.html
您可以使用第二个和第三个参数控制侦听器接收更新的频率-第二个参数是通知之间的最小时间间隔,第三个参数是通知之间距离的最小更改-将这两个参数设置为尽可能频繁地零请求位置通知。
requestLocationUpdates可以满足您的需求。不知道您要对while循环做什么。
发布于 2013-04-03 21:24:27
每10分钟使用一次GPS。
// Des: Start Device's GPS and get current latitude and longitude
public void GPS() throws IOException {
// Des: This is a background service and called after every 10 minutes and fetch latitude-longitude values
background = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < j; i++) {
if (ProjectStaticVariable.GPSExit == true ) {
try {
Thread.sleep(600000); //10 minutes
mainhandler.sendMessage(mainhandler.obtainMessage());
j++;
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
}
});
background.start();
mainhandler = new Handler() {
public void handleMessage(Message msg) {
// Check Internet status
isInternetPresent = cd.isConnectingToInternet();
if (isInternetPresent) {
lat_long_Service_flag = true;
mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener(getApplicationContext());
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, mlocListener);
mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
}
};
}
// Des: Location Listener through which we get current latitude and longitude
public class MyLocationListener implements LocationListener {
public MyLocationListener(Context mContext) {}
public MyLocationListener(Runnable runnable) {}
@Override
public void onLocationChanged(Location loc) {
longitude = loc.getLongitude();
latitude = loc.getLatitude();
final_latitude = Double.toString(latitude);
final_longitude = Double.toString(longitude);
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}https://stackoverflow.com/questions/6166439
复制相似问题