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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:40:42+00:00 2026-05-21T02:40:42+00:00

Following is the code which i am using to find the latitude longitude and

  • 0

Following is the code which i am using to find the latitude longitude and location of a place in my app, but it always show no location found

I have added the permissions in manifest file

{
LocationManager locManager;
setContentView(R.layout.main);
locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locationListener);
    Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if(location != null)                                
     {
        String param = (String)locManager.getProviders(true).get(0);
        Location loc = locManager.getLastKnownLocation(param);

      double latitude = location.getLatitude();
      double longitude = location.getLongitude();
     }  
}

    private void updateWithNewLocation(Location location) 
    {
            TextView myLocationText = (TextView)findViewById(R.id.widget52);
            String latLongString = " ";
            if (location != null) 
            {
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                latLongString = "Lat:" + lat + "\nLong:" + lng;

            } 
            else 
            {
                latLongString = "No location found";
            }
             myLocationText.setText("Your Current Position is:\n" +
                    latLongString);
    }

        private final LocationListener locationListener = new LocationListener() 
        {
            public void onLocationChanged(Location location) 
            {
                updateWithNewLocation(location);
            }

            public void onProviderDisabled(String provider) 
            {
                updateWithNewLocation(null);
            }

            public void onProviderEnabled(String provider) 
            {
            }

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

}

pls help me…

  • 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-21T02:40:43+00:00Added an answer on May 21, 2026 at 2:40 am

    I’ve put your code in an Android project and ran it on the emulator and it seems to be working fine.

    I would change the code to first check for a lastknown location, and after that check for location updates.

    Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    

    If that location is null, or too stale (timestamp) for your needs, you can start requesting location updates. (currently, you’re first requesting location updates from the GPS, and then decide to retrieve its lastknownlocation). This might cause the location manager to stop querying the GPS.

    Also you need to ensure the following is in place :

    For GPS Provider, make sure the following permission is put in the manifest

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

    Ensure the GPS is turned on that you have sufficient GPS coverage.

    Do this by checking for the GPS icon in your Notification bar

    Test on a real device

    Although testing GPS location listeners works partly through the emulator, the behavior of an actual device will always be different.

    Debug on the emulator

    Basic GPS testing can be done using the emulator. Put a breakpoint in your locationlistener, and use the DDMS perspective to send some GPS coordinates to your AVD image.

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

Sidebar

Related Questions

I'm using the following code to find out which part of the page the
I have the following code which works just fine when the method is POST,
I have the following code which works fine. However, I only want to return
Okay so I have the following Code which appends a string to another in
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following JQuery code which does similar functionality like Stackoverflow where the
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have the following JavaScript code: Link In which the function makewindows does not
I have the following code, which will not work. The javascript gives no errors

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.