Aug 4, 2011

Handle both onTap(GeoPoint p, MapView mapView) and onTap(int index) implemented in MapView

Refer to the last two post Detect touch, onTap(int index), on marker in MapView and Detect touch on MapView, onTap(GeoPoint p, MapView mapView); if both callback methods are implemented, onTap(GeoPoint p, MapView mapView) will always captured the event and onTap(int index) will never called.

Handle both onTap(GeoPoint p, MapView mapView) and onTap(int index) implemented in MapView

One of the solution is to call super method in onTap(GeoPoint p, MapView mapView). If super method have handled the event, return with true; otherwise perform as normal.

 @Override
 public boolean onTap(GeoPoint p, MapView mapView) {
  // TODO Auto-generated method stub
  
  if(super.onTap(p, mapView)){
   return true;
  }
  
  String title = "pt:" + String.valueOf(overlayItemList.size() + 1);
  String snippet = "geo:\n"
    + String.valueOf(p.getLatitudeE6()) + "\n"
    + String.valueOf(p.getLongitudeE6());
  
  addItem(p, title, snippet);
  
  return true;
 }

 @Override
 protected boolean onTap(int index) {
  // TODO Auto-generated method stub
  //return super.onTap(index);
  
  Toast.makeText(context,
    "Touch on marker: \n" + overlayItemList.get(index).getTitle(),
    Toast.LENGTH_LONG).show();
  
  return true;
 }

Next:
- Switch Activity once a marker on a MapView tapped


5 comments:

  1. very good post, thanks for the enlightment

    ReplyDelete
  2. Please Reply to the following post:....Dear it is Urgent..You may also reply @ my personal
    Email: shakeelde30@gmail.com;

    ReplyDelete
    Replies
    1. Sorry...post was this one to reply:
      http://learnglobally.wordpress.com/2012/05/20/start-new-activity-in-android-clicking-on-a-marker/

      Delete
  3. Very good article :) but I have a question.
    How to remove that added markers pt1,2,3 and so on?
    And how to move that markers? Is it possible?
    Thanks!

    ReplyDelete

Infolinks In Text Ads