急急急!刚学Android,被分配了修改熄屏后GPS不定位bug,一头雾水,查了很多资料,也没有具体的案例,希望哪位大神解救一下,万分感谢!!!源码如下:
public class Main extends Activity implements OnGeoResultListener, Runnable { Class<?> mActivities[] = { GPSMapView.class, TaskList.class,
HiddenReport.class, PhoneContact.class, SystemSetting.class, null,
AttendanceManager.class, MessageNote.class, Emergency.class };
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Update parameters of this
UpdateMainParameters();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// 位置动态监测
GetCurLocation();
} // 定位
private void GetCurLocation() { this.locationManager = (LocationManager) super
.getSystemService(Context.LOCATION_SERVICE);
if (!this.locationManager
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Toast.makeText(this, "GPS已关闭,请手动开启GPS后再试!", Toast.LENGTH_SHORT)
.show();
return;
} MapView mMapView = (MapView) findViewById(R.id.mapview2);
mMyLocation = new MyOverlay(this, mMapView);
mMyLocation.enableCompass(); // 开启指南针功能
mMyLocation.enableMyLocation();// 开启GPS定位功能 // 获取定位方式
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // 使用最准确精度
criteria.setCostAllowed(false); // 不产生费用
criteria.setPowerRequirement(Criteria.POWER_LOW); // 耗电量低
String provider = this.locationManager.getBestProvider(criteria, true); // 注册位置更新监听
locationManager.requestLocationUpdates(provider,
configure.getLocationUpdateTime(), 5, mMyLocation);
} // 天地图定位
class MyOverlay extends MyLocationOverlay {
public MyOverlay(Context context, MapView mapView) {
super(context, mapView);
// TODO Auto-generated constructor stub
} @Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
super.onLocationChanged(location);
if ((location == null) && (configure.getSavePosition())) {
Toast.makeText(Main.this, "位置获取异常", Toast.LENGTH_SHORT).show();
}
if (location != null) {
// 根据经纬度解析地址
TGeoDecode decode = new TGeoDecode(Main.this);
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1000000),
(int) (location.getLongitude() * 1000000));
decode.search(point);
XCoordinate = location.getLongitude();
YCoordinate = location.getLatitude();
ZCoordinate = location.getAltitude();
// 统计卫星数
GpsStatus state = locationManager.getGpsStatus(null);
Iterable<GpsSatellite> iterable = state.getSatellites();
Iterator<GpsSatellite> iterator = iterable.iterator();
int count = 0;
while (iterator.hasNext()) {
count++;
iterator.next();
}
try {
if (sateliteTxt != null) {
sateliteTxt.setText("卫星数:" + count);
}
} catch (Exception e) {
}
// 与上一点相等则不记录
Location locationDBTemp = configure.getTempLocation();
if (locationDBTemp != null) {
if (locationDBTemp.getLongitude() == location
.getLongitude()
&& locationDBTemp.getLatitude() == location
.getLatitude()
&& locationDBTemp.getAltitude() == location
.getAltitude()) {
return;
}
} // 计算距离
Double lon = null;
Double lat = null;
float[] results = new float[1];
// String
// firstLocation=configure.getFirtLocation(configure.getUserId(),configure.getCurrentPlanInfoID());
if (locationDBTemp != null) {
lon = locationDBTemp.getLongitude();
lat = locationDBTemp.getLatitude();
Location.distanceBetween(lat, lon, location.getLatitude(),
location.getLongitude(), results);
float dis = results[0];
// 取小数
DecimalFormat df = new DecimalFormat("#.#####");
String tempCurrentDateTimeString = sDateFormat
.format(new Date());// 获取位置当前时间
Date date;
long cur_time = 0;
try {
date = sDateFormat.parse(tempCurrentDateTimeString);
cur_time = date.getTime();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long start_time = configure.getUploadStartTime();
long delt = (cur_time - start_time) / 1000; if (dis > 30 && delt > 5) {
dis = 0;
}
String s = df.format(dis);
distance = s;
} else {
distance = "0.0";
} configure.setTempLocation(location);
if (configure.getSavePosition()) { // 判断任务开启状态,为True时记录轨迹坐标 if (location.getAccuracy() < configure.getServerAccuracy()) {
// 判断用户登陆信息是否丢失
if (configure.getUserId() == null) {
configure.systemAutoLogin();
}
String tempCurrentDateTimeString = sDateFormat
.format(new Date());// 获取位置当前时间
Date date;
long cur_time = 0;
try {
date = sDateFormat.parse(tempCurrentDateTimeString);
cur_time = date.getTime();
} catch (ParseException e) {
}
String netWorkAvailable = String.valueOf(Common
.networkAvailable(Main.this));
String netWorkConnected = String.valueOf(Common
.networkConnected(Main.this));
locationDB.insert("location_table",
configure.getUserId(),
configure.getCurrentPlanInfoID(),
String.valueOf(location.getLongitude()),
String.valueOf(location.getLatitude()),
String.valueOf(location.getAltitude()),
configure.getLocalBattery(),
location.getProvider(),
String.valueOf(location.getAccuracy()),
String.valueOf(location.getTime()),
String.valueOf(location.getSpeed()), address,
tempCurrentDateTimeString, netWorkAvailable,
netWorkConnected, distance); // 添加数据到数据库 long start_time = configure.getUploadStartTime();
long delt = (cur_time - start_time) / 1000;
long updata_time = configure.getUpdataTime();
if (delt > updata_time) {
String currentPlanInfoIDValue = configure
.getCurrentPlanInfoID();
if (currentPlanInfoIDValue != null) {
if (upLocThread == null) {
upLocThread = new Thread(Main.this);
upLocThread.setName("upLocThread");
upLocThread.start();
} else if (!upLocThread.isAlive()) {
mHandler.removeCallbacks(upLocThread);
upLocThread = new Thread(Main.this);
upLocThread.setName("upLocThread");
upLocThread.start();
}
}
}
}
}
}
}
}

@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread t = Thread.currentThread();
String name = t.getName();
if (name.equals("upLocThread")) {
if (configure.coordinateUpdate(locationDB) == 0) {
mHandler.sendEmptyMessage(3);
}
} else {// name:"updateParm" mainParameters = configure.getMainParameters(configure
.getUserId());
mHandler.sendEmptyMessage(1); // 记住任务号任务开启时间任务数信息
SharedPreferences sharedPreferences = getSharedPreferences(
Configure.fileName, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("CurrentPlanInfoID",
configure.getCurrentPlanInfoID());
editor.putBoolean("SavePosition", configure.getSavePosition());
editor.putInt("ToggbtnOpenNum", configure.getToggbtnOpenNum());
editor.commit();
} } catch (Exception e) {
mHandler.sendEmptyMessage(2);
}
}}