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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:56:55+00:00 2026-05-24T09:56:55+00:00

I am trying to retrieve my current location on the button click in an

  • 0

I am trying to retrieve my current location on the button click in an editbox using gps or network..i have tried all possible methods which i found in tutorials and older posts….but my location is always null..
i am not getting where i am wrong.?
i am testing it on real device having network but no internet/gprs…

this is the code which i am using..i tried the same with GPS_PROVIDER as well ..please help me..

     protected void showCurrentLocation() 
   {
     geocoder = new Geocoder(this); 
     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     locationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, 
                MINIMUM_TIME_BETWEEN_UPDATES, 
                MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
                new MyLocationListener()
        );

   Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
   System.out.println("loc.."+location);
   if (location != null) 
   {
   String message = String.format("Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude());
       Toast.makeText(ShowActivity.this, message,
               Toast.LENGTH_LONG).show();
  //acTextView.setText(message);
   try {
          List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); //<10>
          for (Address address : addresses) {
              System.out.println("my location .."+address.getAddressLine(0));
            acTextView.setText(address.getAddressLine(0));
          }



        } catch (IOException e) {
          Log.e("LocateMe", "Could not get Geocoder data", e);
        }
    }
    else
    {
    AlertDialog.Builder alertbox1 = new AlertDialog.Builder(this);
    alertbox1.setMessage("No GPS or network ..Signal please fill the location manually!");
    alertbox1.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) 
    {}});
    alertbox1.show();
    }

}   

I am just editing the question instead of asking the new one..because my problem is still related to the same…i didn’t change anything in the code and this is working perfectly fine now…..But the issue is when i use the GPS_PROVIDER ,it returns the accurate address along with the value of longitude and latitude..but when i use NETWORK_PROVIDER it returns only the value of longitude and latitude no address…i want to retrieve the full address using NETWORK_PROVIDER because GPS not works indoor …How can i do that?

Thanks…!!

  • 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-24T09:56:56+00:00Added an answer on May 24, 2026 at 9:56 am

    pleas check your manifest file.whether have you added those permissions or not.

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

    See the updated answer:

    protected void showCurrentLocation() 
           {
             geocoder = new Geocoder(this); 
             locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
             locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER, 
                        MINIMUM_TIME_BETWEEN_UPDATES, 
                        MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
                        myLocationListener
                );
             timer = new Timer();
             timer.schedule(new GetLastLocation(),20000);
    
           }
    
         class GetLastLocation extends TimerTask {
    
                @Override
                public void run() {
                    timer.cancel();
                    locationManager.removeUpdates(locationListener);
                     Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                       System.out.println("loc.."+location);
                       if (location != null) 
                       {
                       String message = String.format("Location \n Longitude: %1$s \n Latitude: %2$s",
                                    location.getLongitude(), location.getLatitude());
                           Toast.makeText(ShowActivity.this, message,
                                   Toast.LENGTH_LONG).show();
                      //acTextView.setText(message);
                       try {
                              List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); //<10>
                              for (Address address : addresses) {
                                  System.out.println("my location .."+address.getAddressLine(0));
                                acTextView.setText(address.getAddressLine(0));
                              }
    
    
    
                            } catch (IOException e) {
                              Log.e("LocateMe", "Could not get Geocoder data", e);
                            }
                        }
                        else
                        {
                        AlertDialog.Builder alertbox1 = new AlertDialog.Builder(this);
                        alertbox1.setMessage("No GPS or network ..Signal please fill the location manually!");
                        alertbox1.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) 
                        {}});
                        alertbox1.show();
                        }
                    }   
                    return;
                }
            }
    
         /** The location listener. */
            LocationListener myLocationListener = new LocationListener() {
    
                public void onLocationChanged(Location location) {
    
                }
                public void onProviderDisabled(String provider) {}
                public void onProviderEnabled(String provider) {}
                public void onStatusChanged(String provider, int status, Bundle extras) {}
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to retrieve the file location from the current itunes track with
I'm trying to retrieve listings that are near a user's current lat/long position. Have
Possible Duplicate: Retrieving Android API version programmatically I am trying to retrieve the current
On a intranet ASP .NET (C#) page I am trying to retrieve the current
I'm trying to retrieve a file from a server using SFTP (as opposed to
Basically I am trying to retrieve a list of stored procedure parameters using Linq
I'm not the greatest with LINQ, but I'm trying to retrieve all the ModuleAvailabilities
i'm trying to retrieve the current date via unix time like this: long unixTime
I'm trying to retrieve the entire rectangle of a scrollable window using the WIN32
I'm trying to retrieve current video position from IMediaSeeking interface. The time format set

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.