【问题标题】:How to add text below/above in the middle of the polyline in osmdroid如何在osmdroid中的折线中间添加下方/上方的文本
【发布时间】:2016-12-02 15:11:52
【问题描述】:

如何在osmdroid中的折线中间添加下方/上方的文本? setTitle() 不起作用,setSubDescription() 也不起作用。
还有如何添加按钮叠加层。

【问题讨论】:

    标签: android-studio osmdroid


    【解决方案1】:

    有一种方法可以做到这一点,它是 Marker 类的一个可选功能。查找示例的最简单方法是使用 LatLonGridOverlay。我将在下面将逻辑简化为易于理解的内容。关键是代码的顺序,看标题,然后把icon设置为null,再添加到map中。您必须根据折线的坐标确定您希望标记的位置,但它确实有效。

    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
    

    source

    【讨论】:

    • 我在我的代码下面添加了它,但我仍然看不到它
    【解决方案2】:

    单独将图标设置为 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      相关资源
      最近更新 更多