當設備通過網絡提供商獲取位置信息時,我可以獲取經度和緯度並將它們轉換爲地址,但當我使用gps時會失敗。我能做些什麼來解決這個問題?未能通過GPS獲取經度和緯度,但通過Android中的網絡提供商獲取?
public void onCreate(Bundle savedInstanceState) {
...
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (mLocation != null) {
gp1 = getGeoByLocation(mLocation);
gp2 = gp1;
refreshMapView();
if(!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000,
10, mLocationListener);
}else{
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000,
10, mLocationListener);
}
private GeoPoint getGeoByLocation(Location location) {
GeoPoint gp = null;
try {
if (location != null) {
double geoLatitude = location.getLatitude() * 1E6;
double geoLongitude = location.getLongitude() * 1E6;
gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);
}
} catch (Exception e) {
e.printStackTrace();
}
return gp;
}
有什麼問題?你在日誌中看到什麼? – 2011-06-14 15:06:42
無法顯示有關經度和緯度的字符串,也是當我使用GPS時指出我的位置的圖像;( – 2011-06-14 15:15:03