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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:42:56+00:00 2026-06-03T14:42:56+00:00

I am trying to get the location in my Android app as follows LocationManager

  • 0

I am trying to get the location in my Android app as follows

LocationManager lmanager = (LocationManager)context.GetSystemService(Context.LocationService);
if (lmanager.IsProviderEnabled(LocationManager.NetworkProvider))
 {
  Location currentLoc = lmanager.GetLastKnownLocation(LocationManager.NetworkProvider);
}

I tried with LocationManager.gpsProvider also instead of the Network provider.

In all the cases I am getting a null reference exception for currentLoc.

  • 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-03T14:43:00+00:00Added an answer on June 3, 2026 at 2:43 pm

    The GetLastKnownLocation() method returns the last location it knew about, which could be null if it has never received any updates before. I think what you want to do here is listen for location updates, and then respond to them once they come in. You can do this by implementing the ILocationListener interface:

    class MyLocationListener : Java.Lang.Object, ILocationListener
    {
        public void OnLocationChanged(Location location)
        {
        }
    
        public void OnProviderDisabled(string provider)
        {
        }
    
        public void OnProviderEnabled(string provider)
        {
        }
    
        public void OnStatusChanged(string provider, Availability status, Bundle extras)
        {
        }
    }
    

    In your activity you can declare that you’d like to use this class to start listening for updates like this:

    var locationManager = (LocationManager)GetSystemService(LocationService);
    var locationListener = new MyLocationListener();
    
    locationManager.RequestLocationUpdates(LocationManager.NetworkProvider, 5000, 2, locationListener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my location using it like this: LocationManager myLocationManager = (LocationManager)
I'm trying to publish an app to the Android Market, I get the following
For an Android app, I'm trying to get some info of a specific user
Possible Duplicate: get current location in android I'm trying to make an application for
I am trying to get the location of a user through LocationManager.NETWORK_PROVIDER but it
I am new to android. I am trying to get my location using GPS.
I'm trying to get the location of Window's Local AppData folder in a version-agnostic
I am trying to get the distance between two location using Google Mps API
I am trying to get weather forecast details for 3 days for user location.
I am trying to get the zip code of the users current location.I have

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.