首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尽快获取全球定位系统

尽快获取全球定位系统
EN

Stack Overflow用户
提问于 2011-05-29 15:24:19
回答 2查看 309关注 0票数 1

目前,我正在做的项目,以混乱的gps频率:-)。我喜欢尽快从GPS/Wifi上获取gps信息。我也想让它以尽可能高的频率工作。我的目标是从这些数据中弄乱一个频率。现在我试着这样做

代码语言:javascript
复制
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

有没有更好的方法来获得更快的“采样率”?

EN

回答 2

Stack Overflow用户

发布于 2011-05-29 16:15:28

来自http://developer.android.com/guide/topics/location/obtaining-user-location.html

您可以使用第二个和第三个参数控制侦听器接收更新的频率-第二个参数是通知之间的最小时间间隔,第三个参数是通知之间距离的最小更改-将这两个参数设置为尽可能频繁地零请求位置通知

requestLocationUpdates可以满足您的需求。不知道您要对while循环做什么。

票数 0
EN

Stack Overflow用户

发布于 2013-04-03 21:24:27

每10分钟使用一次GPS。

代码语言:javascript
复制
//  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) {
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6166439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档