android-studioosmdroid

How to add text below/above in the middle of the polyline in osmdroid


How to add text below/above in the middle of the polyline in osmdroid? setTitle() does not work neither is setSubDescription().
And also how to add button overlays.


Solution

  • There is a way to do it and it's an opt in feature of the Marker class. The easiest way to find an example is with the LatLonGridOverlay. I'll reduce the logic to something simple to understand below. The key is the order of code, set the title, then set the icon to null, then add to the map. You'll have to figure out where you want the Marker to be based on the coordinates of the polyline but it does work.

    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