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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:38:09+00:00 2026-05-25T21:38:09+00:00

Possible Duplicate: GPS not update location after close and reopen app on android I

  • 0

Possible Duplicate:
GPS not update location after close and reopen app on android

I know that question is asked already but my problem is that.

every time when I open my app it shows last location not current location

I have a button for current location and i want when i open my app it show current location on map after then when I click on button then it show current location.

so my problem is when i open my app it shows last location but when i press then it shows current location.

code in onCreate()

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

    _locationListener = new CurrentLocationListener(this,this);
    _locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,1,_locationListener );
    _currentGeoPoint = getKnownLocation();
    _currentPosOverlay = new OverlayItem(_currentGeoPoint, "", "");
    Log.d(" overlay", "overlaylast "+_currentGeoPoint);
  //  Toast.makeText(getBaseContext(), "overlay12333vvv "+_currentGeoPoint, Toast.LENGTH_SHORT).show();
    _customOverlay.addOverlay(_currentPosOverlay);
    _mapOverlays.add(_customOverlay);

Code for getKnownLocation()

    // TODO Auto-generated method stub
    Location lastLocation = _locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);


    if(lastLocation == null){
        lastLocation = _locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
    if(lastLocation != null){

        GeoPoint gp = new GeoPoint((int)(lastLocation.getLatitude() * 1e6), (int)(lastLocation.getLongitude() * 1e6));
        last_loc=gp;

        return gp;
    }else {
        return _mapView.getMapCenter();
    }

For the button I called getKnownLocation()

  • 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-25T21:38:09+00:00Added an answer on May 25, 2026 at 9:38 pm

    Of cause it shows your last know location, thats what your code does.

    You need to give the LocationManager some time to find your current location, you can’t expect it to know it without calculating it.

    What you can do is:

    1. Make a AsyncTask.
    2. In preExecute creates a dialog or does something that shows the user that you are looking for the current location.
    3. In backgroundProccess gets a new location.
    4. In postExecute inform the user with the new(current) location.
    5. When you press your button run the AsyncTask.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Enable GPS programatically like Tasker Ok, I know there is same question
Possible Duplicate: A Singleton that is not globally accessible Do you know a good
Possible Duplicate: Programmatically find device support GPS or not? How can I check, is
Possible Duplicate: Enable GPS programatically like Tasker Anybody know how to enable the GPS
Possible Duplicate: how to use foursquare API in android application? This is a question
Possible Duplicate: How can I enable or disable the GPS programmatically on Android? I
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Why is String.Concat not optimized to StringBuilder.Append? One day I was ranting
Possible Duplicate: Is there some ninja trick to make a variable constant after its

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.