为什么location一直为NULL呢?由与是空
double lat = loc.getLatitude(); //径纬度也就得不到了
double lng = loc.getLongitude();
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider); //为null!!!
以下是取得卫星数,可以正常工作
public void onGpsStatusChanged(int event) { // GPS状态变化时的回调,如卫星数
LocationManager locationManager = (LocationManager) GpsActivity.this.getSystemService(Context.LOCATION_SERVICE);
GpsStatus status = locationManager.getGpsStatus(null); //取当前状态
String satelliteInfo = updateGpsStatus(event, status);
myTextView.setText(satelliteInfo);//正常,显示:搜索到卫星个数:16
}
};
private String updateGpsStatus(int event, GpsStatus status) {
StringBuilder sb2 = new StringBuilder("");
if (status == null) {
sb2.append("搜索到卫星个数:" +0);
} else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
int maxSatellites = status.getMaxSatellites();
Iterator<GpsSatellite> it = status.getSatellites().iterator();
numSatelliteList.clear();
int count = 0;
while (it.hasNext() && count <= maxSatellites) {
GpsSatellite s = it.next();
numSatelliteList.add(s);
count++;
}
sb2.append("搜索到卫星个数:" + numSatelliteList.size());
}
return sb2.toString();
}
在AVD上,这也许是好的~因为可以直接send latitiude...
谁有真机能定位的demo,室内能测最好,只需输出当前径纬度既可,感激不尽~