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 9205793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:02:14+00:00 2026-06-18T00:02:14+00:00

I have used the code below and everything is working fine except that onLocationChanged

  • 0

I have used the code below and everything is working fine except that onLocationChanged is called even if I am sitting at the same location .

I thought it should be called only when I am moving right ?

I only want to get the location after I have moved a certain distance.

Please help me out.
Thanks in advance.

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
    this);


}

    @Override
       public void onLocationChanged(Location location) {
           Toast.makeText(this, "Working!", Toast.LENGTH_SHORT).show();
                    if (location != null) {
                            double lat = location.getLatitude();
                            double lng = location.getLongitude();

                            String Text = "Latitud = " + lat + "\nLongitud = " +
     lng;

      Toast.makeText(getBaseContext(),Text,Toast.LENGTH_SHORT).show();
                    }
           }
  • 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-06-18T00:02:15+00:00Added an answer on June 18, 2026 at 12:02 am

    You’re requesting location updates at the shortest possible intervals/distances

    locationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
    this);
    

    This is what the documentation says about those parameters

    ” The location update interval can be controlled using the minTime parameter. The elapsed time between location updates will never be less than minTime, although it can be more depending on the Location Provider implementation and the update interval requested by other applications. “

    The minDistance parameter can also be used to control the frequency of location updates. If it is greater than 0 then the location provider will only send your application an update when the location has changed by at least minDistance meters, AND at least minTime milliseconds have passed. However it is more difficult for location providers to save power using the minDistance parameter, so minTime should be the primary tool to conserving battery life.

    I personally use a minTime of 10 seconds and 10 meters for my app

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000,
                    10, locationListener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the code below to read rfid tag values. try { if
I have used below code to attach quckboook events // Subscribe to UI events...
I have some problem with my cfml website. I have used the below code
I get this error when I run the code below. I have normally used
Little trouble in using css, in the below code, i have used odd and
I used to have a jCarousel of image that worked perfectly fine in the
I have created email functionality view in which everything is working fine, but the
I have everything working on my login except for the admin user. When I
I have used code like this: http://msdn.microsoft.com/en-us/library/dw70f090.aspx to access database before when working in
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,

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.