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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:19:38+00:00 2026-06-03T16:19:38+00:00

This is my mapActivity: public class MapsActivity extends MapActivity { MapView mapView; MapController mc;

  • 0

This is my mapActivity:

public class MapsActivity extends MapActivity 
{    
     MapView mapView; 
     MapController mc;
     GeoPoint p; 
     GeoPoint geopoint;
     GeoPoint geopoint_2;
    /** Called when the activity is first created. */

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


        mapView = (MapView) findViewById(R.id.mapView);
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
        @SuppressWarnings("deprecation")
        View zoomView = mapView.getZoomControls(); 
        zoomLayout.addView(zoomView, 
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(true);
        mapView.setSatellite(true);
        mc = mapView.getController();
        String coordinates[] = {"38.037132", "24.494019"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);

        p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));

        mc.animateTo(p);
        mc.setZoom(9); 


        geopoint_2 =  new GeoPoint((int) (39.204449 *1E6), (int) (24.307251* 1E6));
        mapView.getOverlays().add( new  DrawableMapOverlay(this,p,R.drawable.pushpin, "test"));
        mapView.getOverlays().add( new  DrawableMapOverlay(this,geopoint_2,R.drawable.pushpin, "test_2"));
        mapView.invalidate();



    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

and this is my DrawableMapOverlay

public class DrawableMapOverlay extends Overlay {

  private static final double MAX_TAP_DISTANCE_KM = 3;
  // Rough approximation - one degree = 50 nautical miles
  private static final double MAX_TAP_DISTANCE_DEGREES = MAX_TAP_DISTANCE_KM * 0.5399568 * 50;
  private final GeoPoint geoPoint;
  private final Context context;
  private final int drawable;
  private final String workerName;
  /**
   * @param context the context in which to display the overlay
   * @param geoPoint the geographical point where the overlay is located
   * @param drawable the ID of the desired drawable
   */
  public DrawableMapOverlay(Context context, GeoPoint geoPoint, int drawable,String workerName) {
    this.context = context;
    this.geoPoint = geoPoint;
    this.drawable = drawable;
    this.workerName = workerName;
  }

  @Override
  public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
    super.draw(canvas, mapView, shadow);

    // Convert geo coordinates to screen pixels
    Point screenPoint = new Point();
    mapView.getProjection().toPixels(geoPoint, screenPoint);
    Paint paint = new Paint();
    // Read the image
    Bitmap markerImage = BitmapFactory.decodeResource(context.getResources(), drawable);
    paint.setStrokeWidth(1);
    paint.setARGB(150, 000, 000, 000);
    paint.setStyle(Paint.Style.STROKE);
    // Draw it, centered around the given coordinates
    canvas.drawBitmap(markerImage,
        screenPoint.x - markerImage.getWidth() / 2,
        screenPoint.y - markerImage.getHeight() / 2, null);
    canvas.drawText(workerName, screenPoint.x- markerImage.getWidth() / 2,  screenPoint.y - markerImage.getHeight() / 2 , paint);
    return true;
  }

  @Override
  public boolean onTap(GeoPoint p, MapView mapView) {
    // Handle tapping on the overlay here
      System.out.println("here is is clicked");
     // final Intent myIntent = new Intent(getApplicationContext(), Places.class);
      new AlertDialog.Builder(context)
              .setTitle("Title")
             .setMessage("Beach")
              .setPositiveButton("Yes",
                      new DialogInterface.OnClickListener() {
                         // @Override
                          public void onClick(DialogInterface dialog, int which) {
                         }
                      })
              .setNegativeButton("No",
                      new DialogInterface.OnClickListener() {
                         // @Override
                          public void onClick(DialogInterface dialog, int which) {
                          }

                      }).show();
    return true;
  }
}

I want when tapping on a marker, see the alert dialog and if i press yes do something. The problem is that the onTap gets called whenever I do Tap, not only on the markers (if I press on an irrelevant point of the map I see the alert dialog, too.)

Any help?

  • 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-03T16:19:40+00:00Added an answer on June 3, 2026 at 4:19 pm

    You need to override the onTap(int) method where int is the index of the overlay item.
    From the docs of onTap(GeoPoint, MapView):

    Handle a tap event. A tap will only be handled if it lands on an item, and you have overridden onTap(int) to return true.

    So basically instead of using onTap(GeoPoint,MapView), use onTap(int).

    • Example usage
    • Check out part 2 here
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mapview class which extends MapActivity. The code i'm using follows the
I've tried to mark multiple locations on my mapview. There is, a class extends
This is my MapActivity Class, it should read the address from the string, reverse
When I create a MapActivity I got this error 05-15 23:31:37.231: E/AndroidRuntime(760): FATAL EXCEPTION:
I have this situation where i have to start an activity from my mainActivity.
I'm trying to make something like this: I have a mapactivity and when the
I have set up a MapView Class which has Overlays (and they're working fine.)
I'm trying to implement a custom MapView. Inside my MapActivity (named mainmap) I have
So I have this code in my main activity to start a new one:
I use below code to show folder list in AlertDialog: ListDialog = new AlertDialog.Builder(MyActivity.this);

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.