在我的應用程序我能夠使用GPS,但問題是,它總是讓我相同的位置。每次我從這個位置檢索位置時,它都會給我同樣的價值。第一次它被取出,我無線上網。然後,我只帶GPS出去了,即使我離開一英里遠,地點也一樣。我啓用了3G,仍然是一樣的。GPS讓我只有一個位置,永遠不會改變Android
我把我的應用程序發送給我的一個朋友,他得到了不同的第一次的位置,然後他看到相同的,無論他去哪裏。
這裏是我的代碼:
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
// System.out.println("Network enabled");
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
// System.out.println("GPS enabled");
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
@Override
public void onLocationChanged(Location location) {
// mAct.playToastMessage("Location Changed");
getLocation();
// mAct.setGPSText(location.getLatitude(),location.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
請檢查[**此**](http://rdcworld-android.blogspot.in/2012/01/get-current-location-coordinates-city.html)我每次都得到新的GPS數據 – swiftBoy