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

  • Home
  • SEARCH
  • 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 8429485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:21:09+00:00 2026-06-10T05:21:09+00:00

This code is used on the onCreate block in my MapActivity lm = (LocationManager)

  • 0

This code is used on the onCreate block in my MapActivity

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
        {
            Toast.makeText(this,
                    "Por favor, habilita el GPS antes de usar esta opción",
                    Toast.LENGTH_SHORT).show();
            finish();
        }
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        doYourMapMagicBaby(loc);

No matter what, loc always returns null. Anyway, when I register for updates on the GPS, the logcat logs my position correctly.

08-24 09:21:18.479: D/libloc(260): Latitude:  40.4399979 (intermediate)
08-24 09:21:57.500: D/libloc(260): Longitude: -3.6700022

So I thought I could implement what I want to do via the onLocationChanged() method. No luck either.

public void onLocationChanged(Location location)
{
    if (location != null)
    {
        System.out.println("La localizacion es: (lon: "
                + location.getLongitude() + ", lat: "
                + location.getLatitude() + ")");
        doYourMapMagicBaby(location);
    }
    else
    {
        System.out.println("La location es nula");
    }

}

What am I doing wrong?

  • 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-10T05:21:11+00:00Added an answer on June 10, 2026 at 5:21 am

    Please check out whether, provider is currently enabled because If the provider is currently disabled, null is returned.
    http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)

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

Sidebar

Related Questions

I have an activity that extends MapActivity, and inside onCreate() I have this code
This code used to return my local ip address as 192.xxx.x.xxx but now it
This code used to work but doesnt any more. i used a breakpoint, and
This code used to work. Then, maybe I changed something, somewhere (or if I
...at least to me. This code used to work fine. I'm pretty sure nothing
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I've used this code for a while now for a few sites I've built
I've used this code https://github.com/johannilsson/android-pulltorefresh It all works perfectly apart from one thing, when
This piece of code used to work in MVC 1 but it does not
I have used this code for extracting urls from web page.But in the line

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.