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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:08:28+00:00 2026-06-03T03:08:28+00:00

i have some code : manifest <uses-permission android:name=android.permission.ACCESS_FINE_LOCATION /> <uses-permission android:name=android.permission.ACCESS_COARSE_LOCATION /> activity fields

  • 0

i have some code :

manifest

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

activity fields

 private LocationManager locationManager;
 private LocationListener mlocListener;

onCreate initialization

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

class MyLocationListener

    public class MyLocationListener implements LocationListener{

        @Override
        public void onLocationChanged(Location loc){
        }


        @Override

        public void onProviderDisabled(String provider){
            Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
        }

        @Override
        public void onProviderEnabled(String provider){
            Toast.makeText( getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
        }


        @Override

        public void onStatusChanged(String provider, int status, Bundle extras){
        }

    }

and i have button, onclick = getting users gps location

public void getUserLocation(View v){
    boolean enabled = locationManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);

    if (!enabled) {
          Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
              startActivity(intent);
    } else {
            Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            Toast.makeText(getApplicationContext(), String.valueOf(location.getLatitude()) + " " + String.valueOf(location.getLongitude()), Toast.LENGTH_SHORT).show();
    }
}

on getLastKnownLocation i have error. how can i check that locationManager has getLastKnownLocation ?? requestLocationUpdates automatic has to get location, hasnt it ??

And im interesting, which parametrs in requestLocationUpdates (minTime and minDistance) should better to use ?? i dont want eat users battery too much

  • 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-03T03:08:28+00:00Added an answer on June 3, 2026 at 3:08 am

    how can i check that locationManager has getLastKnownLocation ??

    Just a null check will do the required

    requestLocationUpdates automatic has to get location, hasnt it ??

    As soon you request either from network or from Gps. It start looking for location updates.
    but it can take times.

    Gps updates are more slower to come. Need open sky but are more accurate.

    network update are more faster to come. but are less accurate as compare to GPS.
    Incase of wifi network accuracy comes around 50-100 which is good for most of the scnario.

    And im interesting, which parametrs in requestLocationUpdates (minTime and minDistance)
    should better to use ?? i dont want eat users battery too much

    use 0,0
    as soon you get a update of desired accuracy unregister from listening location updates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code here that uses bitsets to store many 1 bit values
I have android code that uses a background process to routinely (e.g. hourly) connect
I have some simple code which should create a database. package com.webfoo.android.databaseExample; import android.app.Activity;
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some code that will change the background color of a specific label
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after
I have some code which takes strings representing hexadecimal numbers - hex colors, actually
I have some code that runs a model in a loop. Each iteration of

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.