有没有什么简单的方法,如何判断,是否已经采集到GPS信号?我正在计算期望位置和我当前位置之间的距离,如果没有GPS修复,我想显示错误消息。问题是-如何简单地检查我是否有位置?
谢谢
发布于 2012-06-15 17:57:15
像这样听一下修复方法:
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();
}
}玩得开心!
https://stackoverflow.com/questions/11047375
复制相似问题