1

Currently I have a series of markers on a google map. I want to be able to get the latitude and longitude from anywhere I longclick on the map and I want to open a message box dialog when I quick click on a marker. My issue is that by setting up longpress to work it makes it so my onTap function only gets called when I longclick. Is it possible for longlick to work only when I'm not clicking on a marker?

@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) 
{   

    return gestureScanner.onTouchEvent(event);
    //return false;
} 

////////////////////////////////////
// Handle the clicking of a marker
// 
////////////////////////////////////
@Override
protected boolean onTap(int index) 
{
    System.out.println("OnTap");
    OverlayItem item = mOverlays.get(index);
    int localLat = item.getPoint().getLatitudeE6();
    int localLong = item.getPoint().getLongitudeE6();
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    // Get the titles
    dialog.setTitle(item.getTitle());

    // Get the text for the message
    //dialog.setMessage(item.getSnippet());
    dialog.setMessage("Latitude: " + localLat + "\nLongitude: " + localLong);
    dialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() 
    {   
        public void onClick(DialogInterface dialog, int which) 
        {
            // TODO Auto-generated method stub      
        }
    });
    dialog.show();
    return true;
}

 @Override
public void onLongPress(MotionEvent e)
{
    long downTime = e.getDownTime();
    System.out.println("Down time: " + downTime);
    System.out.println("LongPress Registered");
    GeoPoint p = localMapView.getProjection().fromPixels((int) e.getX(), (int) e.getY());
    System.out.println("Latitude = " + p.getLatitudeE6() + " Longitude: " + p.getLongitudeE6());
}
Geeklat
  • 167
  • 1
  • 2
  • 12

1 Answers1

0

Here's something similar here that might be helpful. You can also override the onTouchEvent() of the Overlay to handle each.

Community
  • 1
  • 1
dbryson
  • 6,047
  • 2
  • 20
  • 20
  • I'm overriding onTouchEvent(), but that's to set up the GestureDetector. Is there a way to let an onTap Event still occur naturally? This is all based on an ItemizedOverlay. Posting code in a second for better concept. – Geeklat May 13 '11 at 19:04
  • How about moving the LongPress to another Overlay that just handles that since it appears to be just displaying pressed coordinates. You can have more than one Overlay at a time. You could simply use a GestureDetector.SimpleOnGestureListener - you would only need to implement the LongPress method and you can remove the GestureDetector from the ItemizedOverlay. – dbryson May 14 '11 at 02:29