我有一個需要得到GPS位置,每20秒左右,但忽略了需要有用戶移動的米一定數量時,我嘗試了minDistance纔會設置爲零,但仍然沒有運氣,其只有當我使用位置控制手動發送位置從DDMS,這被激活和位置得到更新。的Android requestLocationUpdates沒有minDistance纔會
注 - 這是運行和模擬器測試,而不是真正的設備,至少目前
private final static Long INTERVAL_TIME = new Long(20);
private final static Float METERS_MOVED_VALUE = 0f;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.journey);
Bundle dataBundle = this.getIntent().getExtras();
try {
driverData = new JSONObject(dataBundle.getString("driverData"));
} catch (JSONException e) {
e.printStackTrace();
}
//Set the UI elements into variables
journeyDescription = (TextView)findViewById(R.id.journeyDescription);
journeyText = (TextView)findViewById(R.id.journeyText);
confirmButton = (Button)findViewById(R.id.btnCheck);
//Acquire a reference to the system Location Manager
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
try{
//Until requests are found keep broadcasting the drivers location and checking for requests
if(!foundRequest){
updateDriverLocationAndCheckForNewDriverRequests(location);
}
//Always keep updating the drivers location
Double latitude = location.getLatitude()*1E6;
Double longitude = location.getLongitude()*1E6;
geoPoint = new GeoPoint(latitude.intValue(), longitude.intValue());
}catch(JSONException e){
Toast.makeText(JourneyActivity.this, "An unexpected error occurred", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
//Register the listener with the Location Manager to receive location updates can be either gps provider
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, INTERVAL_TIME, METERS_MOVED_VALUE, locationListener);
}
else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, INTERVAL_TIME, METERS_MOVED_VALUE, locationListener);
}
}
下面是相關的代碼片段,而無需用戶如何觸發聽者任何想法移動或我不必從DDMS位置控制信息發送woild不勝感激
問候, 彌蘭陀
我建議創建一個自己的線程或服務,這要求每20秒最後修復 – 2red13 2011-04-06 15:50:39
我是新到Android所以如果原諒我的無知任,但即使一個線程用於將不LocationListener的還是需要一定的最短時間間隔滿足和一定的最小距離感動? – MilindaD 2011-04-06 16:19:38
你在外面嗎? GPS只適用於天空晴朗的設備。 網絡提供的座標只有準確*我覺得* 100米。 – Ian 2011-04-06 17:01:54