首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -如何确定GPS是固定的

Android -如何确定GPS是固定的
EN

Stack Overflow用户
提问于 2012-06-15 16:46:58
回答 1查看 798关注 0票数 0

有没有什么简单的方法,如何判断,是否已经采集到GPS信号?我正在计算期望位置和我当前位置之间的距离,如果没有GPS修复,我想显示错误消息。问题是-如何简单地检查我是否有位置?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-15 17:57:15

像这样听一下修复方法:

代码语言:javascript
复制
    MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.runOnFirstFix(new Runnable() {
        public void run() {
        }
    });

这是我检查gps是否启用的方法。如果不是,用户会得到asket来启用它。

代码语言:javascript
复制
private void checkGPS() {
    try {
        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception e) {
        Log.d("GPS", "GPS koll misslyckades");
        e.printStackTrace();
    }

    if (!isGPSEnabled) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.alert_start_gps_title))
                .setMessage(getString(R.string.alert_start_gps_message))
                .setCancelable(false)
                .setPositiveButton("Aktivera",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {

                                // Sent user to GPS settings screen
                                final ComponentName toLaunch = new ComponentName(
                                        "com.android.settings",
                                        "com.android.settings.SecuritySettings");
                                final Intent intent = new Intent(
                                        Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                                intent.setComponent(toLaunch);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivityForResult(intent, 1);

                                dialog.dismiss();
                                return;

                            }
                        })
                .setNegativeButton("Avbryt",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                dialog.cancel();
                                finish();
                                return;
                            }
                        });
        AlertDialog gpsAlert = builder.create();
        gpsAlert.show();
    }

}

玩得开心!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11047375

复制
相关文章

相似问题

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