Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid requestLocationUpdates without minDistance
    text
    copied!<p>I have a need to get the gps location every 20 seconds or so, but ignoring the need to have the user move a certain number of meters, I tried setting the minDistance to zero but still no luck, its only when I manually send the location using the location control from DDMS that this gets activated and the location gets updated.</p> <p>Note - This is run and tested from the emulator and not a real device, for now at least</p> <pre><code>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); } } </code></pre> <p>Here is the related code fragment, any ideas on how to trigger the listener without having the user move or me having to send information from the DDMS Location Controls woild be greatly appreciated</p> <p>Regards, Milinda</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload