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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:33:56+00:00 2026-05-23T01:33:56+00:00

I’ve tried to solve this before in another post but was unsuccessful. This is

  • 0

I’ve tried to solve this before in another post but was unsuccessful. This is what I want to accomplish: When the user clicks the gpsbtn it will pull from the gps.printLocation method to get the long / lat. I want to auto populate the edittext but I think I could figure out how to do that with a quick google search. So if I could just store it the coords to a variable that would be all I want but my brain is not working. Full code:

public class Location extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Full Screen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.location);

        // Go button
        Button gobtn = (Button) findViewById(R.id.gobtn);
        final EditText Zipcodeinput = (EditText) findViewById(R.id.Zipcode);
        gobtn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // Edit text validation field
                Pattern pattern = Pattern.compile("[0-9][0-9][0-9][0-9][0-9]"); // string needs 5 digits
                // argument to matcher is string to validate
                Matcher matcher = pattern.matcher(Zipcodeinput.getText()
                        .toString());
                if (!matcher.matches()) // on Success
                {
                    // invalid
                    // pop up ERROR message
                    Toast.makeText(getBaseContext(), " Invalid Input ",
                            Toast.LENGTH_LONG).show();

                } else {
                    // validation successful
                    // Change to Listings Page
                    Intent filterIntent = new Intent(view.getContext(),
                            Listings.class);
                    startActivityForResult(filterIntent, 0);
                }
            }
        });

        // button to get to list view
        Button gpsbtn = (Button) findViewById(R.id.gps); // temp use of gps
                                                            // button
        gpsbtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                // Toast.makeText(getApplicationContext(), "Please wait...",
                // Toast.LENGTH_LONG).show();
                Intent gpsIntent = new Intent(view.getContext(), gps.class);
                startActivityForResult(gpsIntent, 0);

            }

        });

    }
}

Class that I want to pull info from:

public class gps extends Activity implements LocationListener {

    //private static final String[] S = { "Out of Service",
            //"Temporarily Unavailable", "Available" };

    private TextView output2;
    private LocationManager locationManager;
    private String bestProvider;
    double latitude,longitude;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps);
        try {   
        // Get the output UI
        //output = (TextView) findViewById(R.id.output);
        output2 = (TextView) findViewById(R.id.output2);

        // Get the location manager
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        // List all providers:
        List<String> providers = locationManager.getAllProviders();
        for (String provider : providers) {
            printProvider(provider);
        }

        Criteria criteria = new Criteria();
        bestProvider = locationManager.getBestProvider(criteria, false);
        //output.append("\n\nBEST Provider:\n");
        printProvider(bestProvider);

        //output.append("\n\nLocations (starting with last known):");
        Location location = locationManager.getLastKnownLocation(bestProvider);
        printLocation(location);
        }
        catch (Exception e)
        {
            Toast.makeText(getBaseContext(), "Error Getting GPS" , Toast.LENGTH_LONG);
        }

    }

    /** Register for the updates when Activity is in foreground */
    @Override
    protected void onResume() {
        super.onResume();

    }

    /** Stop the updates when Activity is paused */
    @Override
    protected void onPause() {
        super.onPause();
        locationManager.removeUpdates(this);
    }

    public void onLocationChanged(Location location) {
        printLocation(location);
    }

    public void onProviderDisabled(String provider) {
        // let okProvider be bestProvider
        // re-register for updates
    }

    public void onProviderEnabled(String provider) {
        // is provider better than bestProvider?
        // is yes, bestProvider = provider
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        //output.append("\n\nProvider Status Changed: " + provider + ", Status="
            //  + S[status] + ", Extras=" + extras);
    }

    private void printProvider(String provider) {
        //LocationProvider info = locationManager.getProvider(provider);
        //output.append(info.toString() + "\n\n");
    }





    //PRINTS the long and lat. Take out round before release

    private void printLocation(Location location) {
        output2.append("Lat:"+location.getLatitude()+"\nLong: "+location.getLongitude());
        latitude = Math.round(location.getLatitude());
        longitude = Math.round(location.getLongitude());

         Toast.makeText(getBaseContext(), "Lat: " + latitude + "| Long: " + longitude, Toast.LENGTH_LONG).show();



    }

I am so lost! 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-23T01:33:57+00:00Added an answer on May 23, 2026 at 1:33 am

    You could save the co-ordinates to the Shared Prefs which are available to all classes within an application. Shared Prefs

    Or you can create a “Global” Class which extends from the Application class and write your own setter and getter methods to access data stored in this Global class.

    public class MyApp extends Application {
    
          public String string1;
    
          public String getState(){
            return string1;
          }
          public void setState(input){
            this.string1 = input;
          }
    }
    

    To get the data stored from any class use from any other class in the application:

    MyApp appState = ((MyApp)getApplicationContext());
    String x = appState.getState();
    appState.setState(x);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I want to construct a data frame in an Rcpp function, but when I
I need to clean up various Word 'smart' characters in user input, including but
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.