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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:06:50+00:00 2026-06-01T16:06:50+00:00

I have some rough code for my project, and I am trying to get

  • 0

I have some rough code for my project, and I am trying to get the GPS location of the user when a button is pressed and I want the location to be a GeoPoint that I can then pass to a method.

The method is for an Overlay class which draws the Overlay that point. I was using some code from Stack Overflow question How can I obtain the current GPS location?. I have the program set up so that the GeoPoint is added to an array and then it is retreived from that array and added to the method. Is there is a better way of doing this or is there any way of using the point without putting it in an array?

This is the button where the Overlay is added and the GeoPoint is gotten from the array:

Button startBtn = (Button) findViewById(R.id.startBtn);
startBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        getLocation();

        tempOverlay = (MapOverlay) listOfOverlays.get(arrayNumber);
        tempOverlay.addPoint(points.get(pointCount));
        mapView.postInvalidate();
        }
    }
});

This is the getLocation() method which creates the locationManager and requestUpdates.

public void getLocation()
{
    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);

    System.out.println("Get Location Called");
}

This is the onLocationChanged method inside the MyLocationListener class which gets the updates and once I have a location I stop the request for updates.

@Override
public void onLocationChanged(Location loc)
{
    if(loc != null)
    {
           Toast.makeText(getBaseContext(),"LocationChanged : Lat: " + loc.getLatitude()+ " Lng: " + loc.getLongitude(),
            Toast.LENGTH_SHORT).show();
    }

    p = new GeoPoint((int) (loc.getLatitude() * 1E6),(int) (loc.getLongitude() * 1E6));

    points.add(p);
    System.out.println("Point Added to Array");

    LBServicesActivity.this.lm.removeUpdates(this);

    mc.animateTo(p);
    mc.setZoom(18);
}

How would I pass that GeoPoint to the method in the buttonListener without adding it to an array?

  • 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-01T16:06:51+00:00Added an answer on June 1, 2026 at 4:06 pm

    Create a GPS class that gets updated when the location is changed, kind of like this:

    public class GPSData {
        private static double latitude;
        /**
         * @return the latitude
         */
        public static double getLatitude() {
            return latitude;
        }
    
        /**
         * @param latitude the latitude to set
         */
        public static void setLatitude(double l) {
            latitude = l;
        }
    
        private static double longitude;
        /**
         * @return the longitude
         */
        public static double getLongitude() {
            return longitude;
        }
    
        /**
         * @param d the longitude to set
         */
        public static void setLongitude(double d) {
            longitude = d;
        }
    }
    
    
    public static class MyLocationListener implements LocationListener {
        public void onLocationChanged(Location location) {
            setAccuracy(location.getAccuracy());
            setLongitude(location.getLongitude());
            setLatitude(location.getLatitude());
        }
    
        @Override
        public void onProviderDisabled(String provider) {
    
        }
    
        @Override
        public void onProviderEnabled(String provider) {
    
        }
    
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
    
        }
    }   
    

    Then when the user clicks the button access the values of that GPS class

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

Sidebar

Related Questions

I have a Django query and some Python code that I'm trying to optimize
I have some very heavy code to develop and want to make some calculations
I have several strings in the rough form: [some text] [some number] [some more
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to
I have some kind of test data and want to create a unit test
We have some files on our website that users of our software can download.

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.