我可以执行不需要长按的 onTap,但仍为其他事件启用长按吗?

发布于 2024-11-06 22:38:22 字数 1590 浏览 0 评论 0原文

目前我在谷歌地图上有一系列标记。我希望能够从长按地图上的任何位置获取纬度和经度,并且希望在快速单击标记时打开消息框对话框。我的问题是,通过设置长按来工作,它使得我的 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());
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-11-13 22:38:22

此处类似的内容可能会有所帮助。您还可以重写 Overlay 的 onTouchEvent() 来处理每个事件。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文