【问题标题】:HERE-SDK lite drag marker in MapViewMapView 中的 HERE-SDK lite 拖动标记
【发布时间】:2020-02-03 04:46:32
【问题描述】:

我只是在试用 SDK Lite API,我想知道如何将 MapMarker 对象从一个地方拖到另一个地方。我建议,它以某种方式通过禁用默认的 onPan 手势起作用,但实际上问题始于选择现有对象。

到目前为止,这是我的代码:

public void pickMarker(Point2D p) {
    map.getGestures().disableDefaultAction(GestureType.PAN);
    map.pickMapItems(p, 20f, pickMapItemsResult -> {
        if (pickMapItemsResult != null) {
            pickedMarker = pickMapItemsResult.getTopmostMarker();
        } else {
            map.getGestures().enableDefaultAction(GestureType.PAN);
        }
    });
}

public void dragMarker(Point2D p) {
    if (pickedMarker != null) {
        pickedMarker.setCoordinates(map.getCamera().viewToGeoCoordinates(p));
    }
}

public boolean releaseMarker(Point2D p) {

    map.getGestures().enableDefaultAction(GestureType.PAN);
    if (pickedMarker != null) {
        GeoCoordinates newCoordinates = map.getCamera().viewToGeoCoordinates(p);
        pickedMarker.setCoordinates(newCoordinates);
        pickedMarker = null;
        return true;
    }
    return false;
}

虽然这些函数是在 onPanListener 的三种状态下调用的:

mapView.getGestures().setPanListener((gestureState, point2D, point2DUpdate, v) -> {
        if (gestureState.equals(GestureState.BEGIN)) {
            mapViewUIEngine.pickMarker(point2D);
        }
        if (gestureState.equals(GestureState.UPDATE)) {
            mapViewUIEngine.dragMarker(point2DUpdate);
        }
        if (gestureState.equals(GestureState.END)) {
            if (mapViewUIEngine.releaseMarker(point2DUpdate)) {
                regionController.movePoint(0,
                        updateNewLocation(point2D, point2DUpdate);
            }
        }
    });

我现在从Github 的一位开发人员那里知道,返回的是多边形而不是标记(它位于多边形线上,但我怎样才能获得标记呢?

【问题讨论】:

    标签: here-api


    【解决方案1】:

    您可以使用地图标记精确指向地图上的某个位置。

    以下方法将自定义地图标记添加到地图:

    MapImage mapImage = MapImageFactory.fromResource(context.getResources(), R.drawable.here_car);
    
    MapMarker mapMarker = new MapMarker(geoCoordinates);
    mapMarker.addImage(mapImage, new MapMarkerImageStyle());
    
    mapView.getMapScene().addMapMarker(mapMarker);
    

    更多详情请参考

    https://developer.here.com/documentation/android-sdk/dev_guide/topics/map-items.html#add-map-markers

    【讨论】:

    • 这不是问题所在。问题是选择标记。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多