0

GPS信号が取得されたかどうかを判断する簡単な方法はありますか?希望の場所と現在の場所の間の距離を数えています。GPS修正がない場合は、エラーメッセージを表示したいと思います。問題は-私が場所を持っているかどうかを簡単に確認する方法は?

ありがとう

4

1 に答える 1

1

そのような修正を聞いてください:

    MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.runOnFirstFix(new Runnable() {
        public void run() {
        }
    });

これがgpsが有効になっているかどうかを確認するための私の方法です。そうでない場合、ユーザーはそれを有効にするためにasketを取得します。

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();
    }

}

楽しむ!

于 2012-06-15T09:57:15.253 に答える