如何在 OSM(打开地图街道)的 Android 工作室中画一条线(折线)?

How can draw a line(Polyline ) in Android studio in OSM (open map street)?

我想在 OSM 中在两点之间画一条线,但我找不到任何可以帮助我的东西。像 googlemap 中的 Polyline 之类的东西。

public class MainActivity extends Activity  {
    private MapView         mMapView;
    private MapController   mMapController;
    public TextView textView;
    public String longitude;
    public String latitude;
    public Drawable marker;
    private ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay;
    ArrayList<OverlayItem> overlayItemArray;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.osm_main);
        mMapView = (MapView) findViewById(mapview);
        textView = (TextView) findViewById(R.id.textView);

        mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
        mMapView.setBuiltInZoomControls(true);
        mMapController = (MapController) mMapView.getController();
        mMapController.setZoom(16);
        Double latE6 = (52.507621 )* 1E6;
        Double lngE6 = (13.407334 )* 1E6;
        GeoPoint gPt = new GeoPoint(latE6.intValue(), lngE6.intValue());
        mMapController.setCenter(gPt);
}
}

我将此代码放在 onCreate 中这一行之后:

mMapController.setCenter(gPt);

    GeoPoint gPt0 = new GeoPoint(52.507621d, 13.407334d);
    GeoPoint gPt1 = new GeoPoint(52.527621d, 13.427334d);
    PathOverlay myPath = new PathOverlay(Color.RED, this);
    myPath.addPoint(gPt0);
    myPath.addPoint(gPt1);
    mMapView.getOverlays().add(myPath);

注意:在你的观点之后使用 d 。

好吧...只需使用 osmdroid Polyline。

    GeoPoint gPt0 = new GeoPoint(52.507621d, 13.407334d);
    GeoPoint gPt1 = new GeoPoint(52.527621d, 13.427334d);
    Polyline line = new Polyline(this);
    line .addPoint(gPt0);
    line .addPoint(gPt1);
    mMapView.getOverlays().add(line);