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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:43:04+00:00 2026-05-26T16:43:04+00:00

I still have problem with fetching first location on android. I am using Criteria

  • 0

I still have problem with fetching first location on android. I am using Criteria like

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        criteria.setSpeedRequired(true);
        String provider = lm.getBestProvider(criteria, true);

        if(provider!=null && provider.length()>0){
            lm.requestLocationUpdates(provider, 0, 0, this);
        }

I need to stop when first time get location like lm.removeUpdates(this);
Where to put that line of code ? In onLocationChanged ?

  • 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-26T16:43:05+00:00Added an answer on May 26, 2026 at 4:43 pm
    public class GPSLocatorActivity extends Activity {
        double current_lat, current_lng;
        MapView mapView;
        boolean flag = true;
    
        /** Called when the activity is first created. */
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            /* Use the LocationManager class to obtain GPS locations */
    
            LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    
            LocationListener mlocListener = new MyLocationListener();
    
            mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1,
                    mlocListener);
    
        }
    
        /* Class My Location Listener */
    
        public class MyLocationListener implements LocationListener
    
        {
    
    
            public void onLocationChanged(Location loc) {
                current_lat = loc.getLatitude();
                current_lng = loc.getLongitude();
    
                if (flag == true) {
                    flag = false;
                    go(current_lat, current_lng);
    
                }
            }
    
    
            public void onProviderDisabled(String provider) {
                Toast.makeText(getApplicationContext(), "Gps Disabled !!! Please Enable It.",
                        Toast.LENGTH_SHORT).show();
    
            }
    
    
            public void onProviderEnabled(String provider)
    
            {
                Toast.makeText(getApplicationContext(), "Gps Enabled",
                        Toast.LENGTH_SHORT).show();
    
            }
    
    
            public void onStatusChanged(String provider, int status, Bundle extras) {
    
            }
    
        }/* End of Class MyLocationListener */
    
        protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
    
        public void go(double c_lat, double c_lng) {
                  System.out.println("your current Lat :: " + c_lat);    
                  System.out.println("your current Lng :: " + c_lng);
    
                 /*turn of gps now */ 
                   turnGPSOff();
             }
        private void turnGPSOff() {
            String provider = Settings.Secure.getString(getContentResolver(),
                    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    
            if (provider.contains("gps")) { // if gps is enabled
                final Intent poke = new Intent();
                poke.setClassName("com.android.settings",
                        "com.android.settings.widget.SettingsAppWidgetProvider");
                poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
                poke.setData(Uri.parse("3"));
                sendBroadcast(poke);
            }
        }
    
    }/* End of UseGps Activity */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am coming back because i still have problem using JodaTime. After the previous
I still have a problem with the splash screen. I don't want to use
i still have a problem to develop a convenient app to the user. because
I have a problem when trying to update foreign keys. Using the merge function
I'm using Rails 3.1. I'm starting to have a problem -- any time I
I'm currently facing in problem using Core Data. I have two entities A and
I've already read the post Passing data to views using Storyboards, but still have
still have problem with this part of code: @interface MYAccessMp3Tags: NSObject { NSTimeInterval duration;
I still have following problem EXPLAIN EXTENDED SELECT `item`.`id`, `item`.`timestamp`, `item`.`label` FROM item WHERE
I have successfully used APNS in iphone app and still have a problem the

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.