Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6555453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:49:19+00:00 2026-05-25T12:49:19+00:00

I have a need to get the gps location every 20 seconds or so,

  • 0

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.

Note – This is run and tested from the emulator and not a real device, for now at least

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);
    }
}

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

Regards,
Milinda

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:49:20+00:00Added an answer on May 25, 2026 at 12:49 pm

    requestLocationUpdates takes milliseconds, not seconds.
    You should change:

    private final static Long INTERVAL_TIME = new Long(20);
    private final static Float METERS_MOVED_VALUE = 0f;
    

    to:

    private final static int INTERVAL_TIME_SECONDS = 20 * 1000; // 20 seconds
    private final static float INTERVAL_DISTANCE_METERS = 0f; // 0 meters
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GPS device for which I need to get: - the last
i finally reached an app that get's the GPS position of the user, but
I have a problem. In my app i need current location from a user.
I need get all items these have no categories int? categoryId = null; var
I have two tables with a weak relation. I need get a text value
I need to get the td element of a table. I do not have
We need to get data out of an older accounting system. We have received
I have a Unix timestamp that I need to get the individual year, month,
I need to get pointed in the right direction. I have embedded an Iron
I have a QTableView that I need to get the selectionChanged event from. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.