1

目前我在谷歌地图上有一系列标记。我希望能够从我在地图上长按的任何地方获取纬度和经度,并且我想在快速单击标记时打开一个消息框对话框。我的问题是,通过设置 longpress 使其工作,这样我的 onTap 函数只会在我长按时被调用。只有当我不点击标记时,longlick 是否可以工作?

@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());
}
4

1 回答 1

0

这里有类似的东西可能会有所帮助。您还可以覆盖onTouchEvent()Overlay 来处理每个。

于 2011-05-13T18:49:54.443 回答