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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:35:16+00:00 2026-06-16T00:35:16+00:00

I am trying to find my current location for an android project. When the

  • 0

I am trying to find my current location for an android project. When the application is loaded my current location is always null. I have set up the permissions in the manifest etc. When I find the current location I intend to use the coordinates to find distances to other locations on the map. My code snippet is below. Why do i always get a null value?
Here is my code:-

    package com.example.location;
    import android.content.Context;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.location.Location;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapView;
    import android.location.LocationListener;
    import com.google.android.maps.MapController;
    import android.widget.Toast;
    import com.google.android.maps.GeoPoint;

    public class MainActivity extends MapActivity implements LocationListener {

        private MapView mapView;
        private LocationManager locManager;

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState); 
            setContentView(R.layout.activity_main);

            //fetch the map view from the layout
            MapView mapView = (MapView) findViewById(R.id.mapview);

            //make available zoom controls 
            mapView.setBuiltInZoomControls(true);
            //latitude and longitude of Rome
            double lat = 33.6667;
            double lon = 73.1667;

            //create geo point
            GeoPoint point = new GeoPoint((int)(lat * 1E6), (int)(lon *1E6));

            //get the MapController object
            MapController controller = mapView.getController();

            //animate to the desired point
            controller.animateTo(point); 

            //set the map zoom to 13
            // zoom 1 is top world view
            controller.setZoom(13);

            // invalidate the map in order to show changes
            **mapView.invalidate();
            // Use the location manager through GPS
            locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,
                    0, this);
            //get the current location (last known location) from the location manager
            Location location = locManager
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

            if (location != null) {

                Toast.makeText(
                        this,
                        "Current location:\nLatitude: " + location.getLatitude()
                                + "\n" + "Longitude: " + location.getLongitude(),
                        Toast.LENGTH_LONG).show(); }
                else {

                    Toast.makeText(this, "Cannot fetch current location!",
                            Toast.LENGTH_LONG).show();
                }**
              //when the current location is found – stop listening for updates (preserves battery)
                locManager.removeUpdates(this);
        }

        @Override
        protected boolean isRouteDisplayed() {

            return false;

        }
        @Override
        protected void onPause() {
            super.onPause();
            locManager.removeUpdates(this); //activity pauses => stop listening for updates
        }
            @Override
        public void onLocationChanged(Location location) {

        }


        @Override
        public void onProviderDisabled(String provider) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

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

        }

    }
  • 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-16T00:35:17+00:00Added an answer on June 16, 2026 at 12:35 am

    Look at this example. very good example for doing things like you want.

    http://mobile.tutsplus.com/tutorials/android/android-sdk-build-a-mall-finder-app-points-of-interest/

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

Sidebar

Related Questions

Possible Duplicate: get current location in android I'm trying to make an application for
I am trying to find current location, and this is my code. LocationManager mlocManager
i am trying to submit user registration form in android with current location. I
trying to find the current location of my device.code is here. package com.example.location; import
I have been trying to set up a staging machine to run project at
I'm trying to find a good, current css3 gradient reference, including vendor prefixes. I've
I'm trying to re-write an application I have for Windows in Objective-C for my
I'm trying to find out the formula to convert the following GPS location format
Hey guys, I'm having trouble trying to find the user's longitude and location as
I was wondering how we would be able to find the current location 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.