Mapview onTap 未针对 OverlayItem onTap 触发

发布于 2024-11-09 08:23:59 字数 531 浏览 6 评论 0原文

我的应用程序中有一个地图视图,并且所有内容都与 touchEvents 配合得非常好。

然而,为了最大限度地提高应用程序的用户数量,我也一直在尝试添加轨迹球界面功能,但遇到了问题。

当轨迹球处于焦点时,轨迹球会正确滚动地图视图,但是当用户集中在覆盖项目上时,我无法触发 onTap 事件。

当我单击鼠标按钮(我正在使用模拟器)来模拟轨迹球用户的单击(F6 接合轨迹球)时,没有任何反应。 onTrackBallEvent 代码在这种情况下永远不会被触发,鉴于 API 文档说,我希望如此在这种情况下 onTap 应该被触发,但它也不会被触发。

如果我没有以overlayItem为中心,我确实会在onTrackBallEvent中获得ACTION_DOWN和ACTION_UP事件,只有当地图以OverlayItem为中心时,onTrackBallEvent才不会被触发。不幸的是 onTap 事件也不会被触发。显然,当覆盖层位于屏幕中心下方且用户单击轨迹球时,操作系统正在通过这些点击执行某些操作,但如果我能弄清楚它是什么,我就该死了。

有谁知道我应该寻找什么活动?

I have a mapview in my app, and everything is working fabulously with touchEvents.

However to maximize usership of the App, I have been trying to add trackBall interface functionality as well and am running into a problem.

The trackball properly scrolls the mapView around when it is in focus, however I am unable to get the onTap event to fire when the user has centered on an overlay item.

When I click the mouse button (I am using the emulator) to simulate a click by the trackball user (F6 engaged trackball) nothing happens.. The onTrackBallEvent code never gets fired in this situation, which I would expect given the API docs say that the onTap should be fired in this instance, but it doesn't get fired either.

If I am not centered on an overlayItem I do get the ACTION_DOWN and ACTION_UP events in the onTrackBallEvent, it is only when the map is centered on an OverlayItem that the onTrackBallEvent does not get fired. Unfortunately the onTap Events don't get fired either. Obviously the OS is doing something with these clicks when an overlay is under the center of the screen and a user clicks on the trackball, but I will be darned if I can figure out what it is.

Does anyone know what Event I should be looking for?

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

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

发布评论

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

评论(3

青春如此纠结 2024-11-16 08:23:59

这是一个相当老的问题,但我想我会给出 2 美分。由于某种原因,您需要在地图上的某个位置添加叠加层,然后 onTap() 覆盖才能在您单击的位置添加其他叠加层。我用过:

public boolean onTap(GeoPoint p, MapView mapView) {
    boolean tappedAnOverlay = super.onTap(p, mapView);
    if (tappedAnOverlay) {
        // do your thing if hit an overlay
    }
    else {
        // no overlay found in that location
    }

    MapController mc = mapView.getController();
    mc.animateTo(p);

    return true;

} 

This is quite an old issue but figured I'd give my 2 cents. For some reason, you need to add an overlay somewhere on the map before the onTap() override can add other overlays where you click. I used:

public boolean onTap(GeoPoint p, MapView mapView) {
    boolean tappedAnOverlay = super.onTap(p, mapView);
    if (tappedAnOverlay) {
        // do your thing if hit an overlay
    }
    else {
        // no overlay found in that location
    }

    MapController mc = mapView.getController();
    mc.animateTo(p);

    return true;

} 
幻梦 2024-11-16 08:23:59

因为它适用于此。我检查屏幕上的点击点是否与某些覆盖项目匹配。

        public boolean onTouchEvent(MotionEvent event, MapView mv) {
        final int action=event.getAction();
        final int x=(int)event.getX();
        final int y=(int)event.getY();

        if(!this.marker.equals(getResources().getDrawable(R.drawable.parada))){
            if (action == MotionEvent.ACTION_DOWN) {
                        for (OverlayItem item : mItems) {
                        Point p = new Point(0,0);                       
                        mv.getProjection().toPixels(item.getPoint(), p);                        
                        if (hitTest(item, marker, x-p.x, y-p.y) && item.getSnippet()!= "parada") {

For it works with this. I check if the hit point on the screen matches with some overlay item.

        public boolean onTouchEvent(MotionEvent event, MapView mv) {
        final int action=event.getAction();
        final int x=(int)event.getX();
        final int y=(int)event.getY();

        if(!this.marker.equals(getResources().getDrawable(R.drawable.parada))){
            if (action == MotionEvent.ACTION_DOWN) {
                        for (OverlayItem item : mItems) {
                        Point p = new Point(0,0);                       
                        mv.getProjection().toPixels(item.getPoint(), p);                        
                        if (hitTest(item, marker, x-p.x, y-p.y) && item.getSnippet()!= "parada") {
奶茶白久 2024-11-16 08:23:59

请试试这个。这用于在地图视图上显示多个叠加层,可能会解决问题:https://github。 com/donnfelker/android-mapviewballoons

please try this one. This is used for showing multiple overlays on map view, may be it will solve the problem: https://github.com/donnfelker/android-mapviewballoons

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