如何在osmdroid中的折线中间添加文本下方/上方

问题描述 投票:0回答:2

如何在 osmdroid 中的折线中间添加下方/上方文本?

setTitle()
不起作用,
setSubDescription()
也不起作用。
以及如何添加按钮覆盖。

android-studio osmdroid
2个回答
2
投票

有一种方法可以做到这一点,它是 Marker 类的一个选择功能。查找示例的最简单方法是使用 LatLonGridOverlay。下面我将把逻辑简化为简单易懂的内容。关键是代码的顺序,设置标题,然后设置图标为空,然后添加到地图中。您必须根据折线的坐标找出您想要标记的位置,但它确实有效。

Polyline p = new Polyline();
List<GeoPoint> pts = new ArrayList<GeoPoint>();
//add your points here
p.setPoints(pts);

//add to map

Marker m = new Marker(mapView);
m.setTitle("Some text here");
//must set the icon last
m.setIcon(null);
m.setPosition(new GeoPoint(marker location here));

//add to map

来源


0
投票

单独将 icon 设置为 null 对我来说不起作用,我需要使用 setTextIcon:

distanceMarker = new Marker(mapView);
            distanceMarker.setIcon(null);
            distanceMarker.setTextIcon(distance);
            GeoPoint p3 = new GeoPoint((loc.getLatitude()+poi.getLat())/2,(loc.getLongitude()+poi.getLon())/2);
            distanceMarker.setPosition(p3);
            mapView.getOverlayManager().add(distanceMarker);
© www.soinside.com 2019 - 2024. All rights reserved.