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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:24:46+00:00 2026-06-12T06:24:46+00:00

I have an extended overlay class: short code: public class MapOverlay extends Overlay {

  • 0

I have an extended overlay class:

short code:

public class MapOverlay extends Overlay {

private Context context;
private ProgressDialog dDialog;  
Drawable drawable;
GeoPoint MainPoint;
MapView mapView;

public MapOverlay(Context context, MapView mapView)
{
    this.context = context;
    this.mapView = mapView;
}

@Override
public boolean onTap(GeoPoint p, MapView mapView) 
{   
      this.MainPoint = p;
      AlertDialog.Builder dialog = new AlertDialog.Builder(context);
      dialog.setMessage("Do you want to set point here?")
             .setCancelable(false)
   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
         setPoint();

       }
   })
   .setNegativeButton("No", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
       }
   });

      dialog.show();

    return true;
}    

public void setPoint()
{

       OverlayItem overlayitem = new OverlayItem(MainPoint, "Hi!", "You touched this location!");


}

I want to draw the touched point on my mapview, which is in this activity:

public class MyMapLocationActivity extends MapActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.main); 


    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    drawable = this.getResources().getDrawable(R.drawable.androidmarker);           
            MapOverlay myOverlay = new MapOverlay(this, mapView);

    mapView.getOverlays().add(myOverlay);
    mapView.postInvalidate();

}

I want to mark the touched point, after confirming the dialog box from MapOverlay class. I think I’m missing to pass something – what more should I do?

  • 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-12T06:24:47+00:00Added an answer on June 12, 2026 at 6:24 am

    You need to have a class which extends ItemizedOverlay, which in turn can hold an OverlayItem, which takes a GeoPoint in its constructor. Something like

    public class MapDemo extends MapActivity implements OnTouchListener {
    
        private Drawable mDrawable;
        private ItemizedMapOverlay mItemizedOverlay;
        private OverlayItem mOverlayitem;
        private GeoPoint mClickedPoint = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            GeoPoint mapCentrePoint = new GeoPoint(51500000, 0);
            MapView mapView = (MapView) findViewById(R.id.mapview);
            mapView.setOnTouchListener(this);
            MapController mapCtrlr = mapView.getController();
            mapView.setBuiltInZoomControls(true);
            mapCtrlr.setZoom(8);
            mapCtrlr.setCenter(mapCentrePoint);
            List<Overlay> mapOverlays = mapView.getOverlays();
            mDrawable = this.getResources().getDrawable(R.drawable.icon);
            mItemizedOverlay = new ItemizedMapOverlay(mDrawable, this);
            mapOverlays.add(mItemizedOverlay);
        }
    
        @Override
        protected boolean isRouteDisplayed() {return false;}
    
        @Override
        public boolean onTouch(View v, MotionEvent e) {
    
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                final View fv = v;
                AlertDialog.Builder dialog = new AlertDialog.Builder(v
                        .getRootView().getContext());
                dialog.setMessage("Do you want to set point here?")
                        .setCancelable(false)
                        .setPositiveButton("Yes",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                        setPoint(fv);
                                    }
                                })
                        .setNegativeButton("No",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                        dialog.cancel();
                                    }
                                });
    
                dialog.show();
                // Can't show point till +ve button selected, so store it
                mClickedPoint = ((MapView) v).getProjection()
                                .fromPixels((int)e.getX(), (int)e.getY());
            }
            return true;
        }
    
        void setPoint(View v) {
            if (mClickedPoint != null) {
                mOverlayitem = new OverlayItem(mClickedPoint, "test", "test2");
                mOverlayitem.setMarker(mDrawable);
                mItemizedOverlay.clear(); // clear last marker
                mItemizedOverlay.addOverlay(mOverlayitem);
                v.postInvalidate();
            }
        }
    
    }
    

    and

    public class ItemizedMapOverlay extends ItemizedOverlay {
    
        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    
        public  ItemizedMapOverlay(Drawable defaultMarker) {
            super(boundCenterBottom(defaultMarker));
        }
    
        public  ItemizedMapOverlay(Drawable defaultMarker, Context context) {
            super(boundCenterBottom(defaultMarker));
        }
    
        @Override
        protected OverlayItem createItem(int i) {return mOverlays.get(i);}
    
        @Override
        public void draw(android.graphics.Canvas canvas, MapView mapView,
                boolean shadow) {
            super.draw(canvas, mapView, shadow);
        }
    
        @Override
        public int size() { return mOverlays.size();}
    
        public void addOverlay(OverlayItem overlay) {
            mOverlays.add(overlay);
            populate();
        }
    
        public void clear() {
            mOverlays.clear();
        }
    
    }
    

    should be close enough for you to adapt.

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

Sidebar

Related Questions

I have extended the Application class like this: public class MyApplication extends Application {
I have a main class and two extended classes: class Main { public $foo;
I have extended a class like so: public class CormantRadDock : Telerik.Web.UI.RadDock { public
I have extended a server control (not a user control) and put the code
Below is the snippet of my code. I have a JTable. I have extended
I have a custom class called NoteView that extends FrameLayout . Previously, I had
I have extended the ViewPager class and implemented onPageChangeListener. I use this ViewPager in
I have extended PHP's mysqli class, which works fine. But how can I make
I have extended an mxml component with an actionscript class. I'm trying to access
I have extended the standard FileSystemWatcher class by adding a string property (fileToTest), now

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.