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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:22:30+00:00 2026-06-12T23:22:30+00:00

i am trying to capture longitude and latitude values from android phone.i am able

  • 0

i am trying to capture longitude and latitude values from android phone.i am able to display values on my external device but i cont able to display them on my emulator and showing location not found.please tell me good approach to store the values in a text file also ,please, here is my code.I created textfile in my assets folder.

public class MainActivity extends Activity implements LocationListener{

private final static String STORETEXT="storetext.txt";


LocationManager locationManager ;
String provider;
String value1;
String value2;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting LocationManager object
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);        

    // Creating an empty criteria object
    Criteria criteria = new Criteria();

    // Getting the name of the provider that meets the criteria
    provider = locationManager.getBestProvider(criteria, false);


    if(provider!=null && !provider.equals("")){

        // Get the location from the given provider 
        Location location = locationManager.getLastKnownLocation(provider);


        locationManager.requestLocationUpdates(provider, 20000, 1, this);


        if(location!=null)
            onLocationChanged(location);
        else
            Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();

    }else{
        Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public void onLocationChanged(Location location) {
    // Getting reference to TextView tv_longitude
    TextView tvLongitude = (TextView)findViewById(R.id.tv_longitude);

    // Getting reference to TextView tv_latitude
    TextView tvLatitude = (TextView)findViewById(R.id.tv_latitude);

    // Setting Current Longitude
    tvLongitude.setText("Longitude:" + location.getLongitude());

    // Setting Current Latitude
    tvLatitude.setText("Latitude:" + location.getLatitude() );

    value1 = tvLongitude.getText().toString();
    value2 = tvLatitude.getText().toString();

    saveClicked();




}

private void saveClicked() {



    try{
        OutputStreamWriter out=
                new OutputStreamWriter(openFileOutput(STORETEXT, 0));
        out.write(value1);
        out.write(value2);
        out.close();

        Toast
    .makeText(this, "The contents are saved in the file.", Toast.LENGTH_LONG)
    .show();

    }
    catch(Throwable t){
        Toast.makeText(this, "Exception: "+ t.toString(), Toast.LENGTH_LONG)
        .show();

    }
}

@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      
}
}
  • 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-12T23:22:31+00:00Added an answer on June 12, 2026 at 11:22 pm

    On the emulator, geolocation doesn’t work. To test you can still inject a geo fix

    You should not use assets to store this data, you activity.getApplicationContext().getCacheDir() or getFilesDir().

    Then once data is stored locally, you should focus on using a rest service to upload this data to your server and record it into a database.

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

Sidebar

Related Questions

I'm trying to capture an image from the window mobile device using Qt. Is
I'm trying to capture values from the Fibonacci method and concatenate it to an
I'm trying to capture the image from my webcam, but I got the error
I am trying to capture some stream from a device and save it to
I am trying to capture image and video from my android application with the
I am trying to capture / extract numeric values from some strings. Here is
I trying to capture packets using SharpPcap library. I'm able to return the packets
I'm trying to capture packets from two devices on my network. I have tcpdump
I am trying to capture the output from tail in follow mode, where it
I'm trying to capture aa,bb,cc from the following strings: ,aa,bb,cc, aa,bb,cc, ,aa,bb,cc aa,bb,cc My

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.