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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:08:46+00:00 2026-06-10T14:08:46+00:00

public class MyActivity extends MapActivity implements LocationListener, OnClickListener { private MapView mapView; private MyItemizedOverlay

  • 0
public class MyActivity extends MapActivity implements LocationListener, OnClickListener {

    private MapView mapView;
    private MyItemizedOverlay itemizedOverlay;
    Button route;
    boolean shadow;
    private LocationManager locManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        route = (Button) findViewById(R.id.cmd_submit);
        route.setOnClickListener(this);



        //fetch the map view from the layout
        mapView = (MapView) findViewById(R.id.myMapView);

        //make available zoom controls
        mapView.setBuiltInZoomControls(true);



        //latitude and longitude of Rome
        double lat = 41.889882;
        double lon = 12.479267;

        //create geo point
        GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));

        //get the MapController object
        MapController controller = mapView.getController();

        //animate to the desired point
        controller.animateTo(point);

        //set the map zoom to 13
        // zoom 1 is top world view
        controller.setZoom(13);

        //invalidate the map in order to show changes
        mapView.invalidate();



        // Use the location manager through GPS
        locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, this);

        //get the current location (last known location) from the location manager
        Location location = locManager
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);


        //if location found display as a toast the current latitude and longitude
        if (location != null) {

            Toast.makeText(
                    this,
                    "Current location:\nLatitude: " + location.getLatitude()
                    + "\n" + "Longitude: " + location.getLongitude(),
                    Toast.LENGTH_LONG).show();

            point = new GeoPoint((int) (location.getLatitude() * 1E6), (int) (location.getLongitude()
                    * 1E6));

            controller.animateTo(point);


        } else {

            Toast.makeText(this, "Cannot fetch current location!",
                    Toast.LENGTH_LONG).show();
        }

        //when the current location is found – stop listening for updates (preserves battery)
        locManager.removeUpdates(this);

        // fetch the drawable - the pin that will be displayed on the map
        Drawable drawable = this.getResources().getDrawable(R.drawable.marker);

        // create and add an OverlayItem to the MyItemizedOverlay list
        OverlayItem overlayItem = new OverlayItem(point, "", "");

        itemizedOverlay = new MyItemizedOverlay(drawable, this);

        itemizedOverlay.setGestureDetector(new GestureDetector(new MyGestureDetector()));

        itemizedOverlay.addOverlay(overlayItem);


        // add the overlays to the map
        mapView.getOverlays().add(itemizedOverlay);
        mapView.invalidate();

        //when the current location is found – stop listening for updates (preserves battery)
        locManager.removeUpdates(this);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;

    }

    /* When the activity starts up, request updates */
    @Override
    protected void onResume() {
        super.onResume();
        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        locManager.removeUpdates(this); //activity pauses => stop listening for updates
    }
}

And here’s the inner class, the problem is that I want to access this ArrayList of points in the MyActivity class but it seems that I have to make all the variables static which ultimately gives me errors. Any work-around or solution would be greatly appreciated.

public class MyGestureDetector extends SimpleOnGestureListener {

    ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();

    @Override
    public boolean onSingleTapConfirmed(MotionEvent event) {

        // fetch the correspondent point from the map

        Log.d("A condition", "d5al l methodaaya");
        GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());
        points.add(p);




        // create an overlay item and clear all others
        OverlayItem o = new OverlayItem(p, null, null);
        itemizedOverlay.addOverlay(o);

        if (points.size() > 1) {
            Log.d("Points are", "" + points);

        }

        // add the overlay item
        //mapView.getOverlays().clear();
        mapView.getOverlays().add(itemizedOverlay);
        mapView.invalidate();

        Geocoder geoCoder = new Geocoder(getBaseContext(),
                Locale.getDefault());

        // get the address based on the coordinates
        try {
            List<Address> addresses = geoCoder.getFromLocation(p.getLatitudeE6() / 1E6, p.getLongitudeE6()
                    / 1E6, 1);

            String addressString = "";
            if (addresses.size() > 0) {
                for (int i = 0; i < addresses.get(0)
                        .getMaxAddressLineIndex(); i++)
                    addressString += addresses.get(0).getAddressLine(i)
                            + " - ";
            }

            Toast.makeText(getBaseContext(), addressString,
                    Toast.LENGTH_SHORT).show();








        } catch (IOException e) {
            e.printStackTrace();
        }

        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return false;
    }
}

public void onClick(View arg0) {

    //System.out.println(points);
    if (route == arg0) {
        Intent i = new Intent(this, ChoosingClues.class);
        startActivity(i);
    }
}
  • 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-10T14:08:48+00:00Added an answer on June 10, 2026 at 2:08 pm

    You can declare points as field of Activity Class and then you will have access in both the classes.
    Else you cant access fields/variables of inner class in outer class. you can access only static fields of the class.

    SO change your code to the following:

    public class MyActivity extends MapActivity implements LocationListener, OnClickListener {
    
        private MapView mapView;
        private MyItemizedOverlay itemizedOverlay;
        Button route;
        boolean shadow;
        private LocationManager locManager;
        ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            route = (Button) findViewById(R.id.cmd_submit);
            route.setOnClickListener(this);
    
    
    
            //fetch the map view from the layout
            mapView = (MapView) findViewById(R.id.myMapView);
    
            //make available zoom controls
            mapView.setBuiltInZoomControls(true);
    
    
    
            //latitude and longitude of Rome
            double lat = 41.889882;
            double lon = 12.479267;
    
            //create geo point
            GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
    
            //get the MapController object
            MapController controller = mapView.getController();
    
            //animate to the desired point
            controller.animateTo(point);
    
            //set the map zoom to 13
            // zoom 1 is top world view
            controller.setZoom(13);
    
            //invalidate the map in order to show changes
            mapView.invalidate();
    
    
    
            // Use the location manager through GPS
            locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                    0, this);
    
            //get the current location (last known location) from the location manager
            Location location = locManager
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
    
    
            //if location found display as a toast the current latitude and longitude
            if (location != null) {
    
                Toast.makeText(
                        this,
                        "Current location:\nLatitude: " + location.getLatitude()
                        + "\n" + "Longitude: " + location.getLongitude(),
                        Toast.LENGTH_LONG).show();
    
                point = new GeoPoint((int) (location.getLatitude() * 1E6), (int) (location.getLongitude()
                        * 1E6));
    
                controller.animateTo(point);
    
    
            } else {
    
                Toast.makeText(this, "Cannot fetch current location!",
                        Toast.LENGTH_LONG).show();
            }
    
            //when the current location is found – stop listening for updates (preserves battery)
            locManager.removeUpdates(this);
    
            // fetch the drawable - the pin that will be displayed on the map
            Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
    
            // create and add an OverlayItem to the MyItemizedOverlay list
            OverlayItem overlayItem = new OverlayItem(point, "", "");
    
            itemizedOverlay = new MyItemizedOverlay(drawable, this);
    
            itemizedOverlay.setGestureDetector(new GestureDetector(new MyGestureDetector()));
    
            itemizedOverlay.addOverlay(overlayItem);
    
    
            // add the overlays to the map
            mapView.getOverlays().add(itemizedOverlay);
            mapView.invalidate();
    
            //when the current location is found – stop listening for updates (preserves battery)
            locManager.removeUpdates(this);
        }
    
        @Override
        protected boolean isRouteDisplayed() {
            return false;
    
        }
    
        /* When the activity starts up, request updates */
        @Override
        protected void onResume() {
            super.onResume();
            locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                    0, this);
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            locManager.removeUpdates(this); //activity pauses => stop listening for updates
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: public class MyActivity extends Activity implements View.OnClickListener { private Button mHorizontalButton;
Here's my code: public class SomeName extends MapActivity implements OnClickListener, OnTouchListener{ public Timer t1
import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import android.os.Bundle; public class Map2Activity extends MapActivity { /** Called
I've the following code for implementing zoom image in Android: public class MyActivity extends
I am using LocationManager to get a single location fix: public class MyActivity extends
Initially my activity calls new DropboxApi(token).execute(); with token. public class DropboxApi extends AsyncTask<Void, Long,
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class MyClass { public string MyProperty{ get; set; } Now, I would like
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new

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.