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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:29:15+00:00 2026-06-08T02:29:15+00:00

Possible Duplicate: Android AVD wifi error I am working with Android, and I want

  • 0

Possible Duplicate:
Android AVD wifi error

I am working with Android, and I want to show current latitude value in textbox and current longitude value in another textbox. And I wrote the below code, but it is not working. It is not setting any latitude or longitude value in the corresponding textbox. Is there any problem with my code?

public class MainActivity extends Activity implements LocationListener {
    private TextView latituteField;
    private TextView longitudeField;
    private LocationManager locationManager;
    private String provider;

    private static final String TAG = "CurrentLocation";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        latituteField = (TextView) findViewById(R.id.lat1);
        longitudeField = (TextView) findViewById(R.id.lat2);

     // Get the location manager
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        // Define the criteria how to select the location provider -> use
        // default
        Criteria criteria = new Criteria();
        provider = locationManager.getBestProvider(criteria, false);
        locationManager.requestLocationUpdates(provider, 0, 0, this);
        Location location = locationManager.getLastKnownLocation(provider);
        onLocationChanged(location);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        locationManager.removeUpdates(this);
    }

    @Override
    public void onLocationChanged(Location location) {
       if (location != null) {
           System.out.println("Provider " + provider + " has been selected.");
           int lat = (int) (location.getLatitude());
           int lng = (int) (location.getLongitude());
           Log.e("GPS", "location changed: lat="+lat+", lon="+lng);
           latituteField.setText(String.valueOf(lat));
           longitudeField.setText(String.valueOf(lng));
       } else {
           latituteField.setText("Provider not available");
           longitudeField.setText("Provider not available");
       }
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }
}

Or I need to do something such as passing latitude or longitude value from somwhere? Or it will automatically get the current location value?

I have these in my manifest file-

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
    <uses-permission android:name="android.permission.INTERNET" />

Anything else I need to add?

And also I am getting this error when I saw in logCAT

07-18 22:43:59.836: E/Trace(3410): error opening trace file: No such file or directory (2)

I am getting in my textbox as Provider Not Available as it is going to else loop.

  • 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-08T02:29:17+00:00Added an answer on June 8, 2026 at 2:29 am

    As you mentioned in the comment that you are running your code from eclipse. Let me tell you that, can not fetch the real GPS Co-Ordinates in Eclipse. However you can simulate it by load .gpx file in to DDMS.

    Have a visit my answer for same purpose.

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

Sidebar

Related Questions

Possible Duplicate: Android Launch an application from another application I want to start Another
Possible Duplicate: Android: ProgressDialog.show() crashes with getApplicationContext I want to have a progress dialog
Possible Duplicate: Android: How to create slide (on/off) button I want to create sliding
Possible Duplicate: Android Launch an application from another application I am having a problem
Possible Duplicate: Android - how to set the wallpaper image I want to change
Possible Duplicate: Android SMS Receiver not working I am in the beginning stages of
Possible Duplicate: Android :Text Animation I want to know how I can implement the
Possible Duplicate: Disable back button in android i don't want to dismiss my dialog
Possible Duplicate: Android: How can I get the current foreground activity (from a service)?
Possible Duplicate: Android API for Google Drive? I want to synchronize a single small

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.