0
我陷入了一個問題,以獲得在Android設備中的經度和長度。 看看我的代碼如下: -在Android設備中獲取位置的問題
public NewLocationActivity(final Context mContext) {
locationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateLocation(location);
mSharedPreferences=mContext.getSharedPreferences(HomeSAFEPref.HomeSAFELocationPref,Context.MODE_PRIVATE);
SharedPreferences.Editor prefEditor=mSharedPreferences.edit();
String latitude=String.valueOf(currentLatitude);
String longitude=String.valueOf(currentLongitude);
String heading=String.valueOf(currentheading);
String horizAccuracy=String.valueOf(currenthorizAccuracy);
prefEditor.putString("Latitude", latitude);
prefEditor.putString("Longitude", longitude);
prefEditor.putString("Heading", heading);
prefEditor.putString("HorizAccuracy", horizAccuracy);
prefEditor.commit();
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
void updateLocation(Location location) {
currentLocation = location;
this. currentLatitude = currentLocation.getLatitude();
this. currentLongitude = currentLocation.getLongitude();
geoField=new GeomagneticField(
Double.valueOf(location.getLatitude()).floatValue(),
Double.valueOf(location.getLongitude()).floatValue(),
Double.valueOf(location.getAltitude()).floatValue(),
System.currentTimeMillis()
);
this.currentheading=geoField.getInclination();
this.currenthorizAccuracy=currentLocation.getAccuracy();
this.speed=(int) currentLocation.getSpeed();
}
當我創建類NewLocationActivity構造的對象的工作。但我的問題是,更新位置方法不runs.Why我不知道......但有些時候在其他設備它運行完美,我得到lat和long easily.Please讓我知道爲什麼我得到經緯度和長0,0.Thanks提前..
http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ – Ruban