【问题标题】:How to detect the Here SDK map small pans and ignore them如何检测Here SDK地图小平底锅并忽略它们
【发布时间】:2020-04-08 14:49:01
【问题描述】:

我们的应用中有 Here SDK MapFragment,由于用户在地图上的单击可能会解释为平移事件,因此我试图忽略小的平移运动并重新定位地图。

我的第一个问题是MapGesture.OnGestureListeneronPanStart()onPanEnd() 事件没有提供有关平移量(用户手指在屏幕上移动了多少)的任何信息。

然后我开始保存地图中心onPanStart() 并在onPanEnd() 处获取与地图中心的距离,但由于地图是倾斜的并且有时会缩放,因此我无法通过手指移动获得固定距离。

    val distance = lastCenter.distanceTo(mapFragment.map.center)
    if (distance < 80) recenter()

有任何解决方案或更好的想法来实现这个目标吗?

【问题讨论】:

    标签: android dictionary sdk here-api


    【解决方案1】:

    使用 mapView.getCamera() 返回的 Camera 来操作地图的视图。使用 geoToViewCoordinates() 和 viewToGeoCoordinates() 在视图和地理坐标空间之间进行转换。

    private void setLongPressGestureHandler(MapViewLite mapView) {
        mapView.getGestures().setLongPressListener(new LongPressListener() {
            @Override
            public void onLongPress(@NonNull GestureState gestureState, @NonNull Point2D touchPoint) {
                GeoCoordinates geoCoordinates = mapView.getCamera().viewToGeoCoordinates(touchPoint);
    
                if (gestureState == GestureState.BEGIN) {
                    Log.d(TAG, "LongPress detected at: " + geoCoordinates);
                }
    
                if (gestureState == GestureState.UPDATE) {
                    Log.d(TAG, "LongPress update at: " + geoCoordinates);
                }
    
                if (gestureState == GestureState.END) {
                    Log.d(TAG, "LongPress finger lifted at: " + geoCoordinates);
                }
            }
        });
    }
    

    【讨论】:

    • 什么是MapViewLite?我在这里 Android SDK 中没有它。我只能使用AndroidXMapFragment 访问mapGesturemap。另外,我说的是水龙头和平底锅,这段代码是关于 LongPress 的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 2022-12-16
    • 1970-01-01
    相关资源
    最近更新 更多