如何在OSM(开放地图街道)中的Android studio中绘制一条线(Polyline)?

Moh*_*beh 3 android openstreetmap osmdroid

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

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);
}
}
Run Code Online (Sandbox Code Playgroud)

MKe*_*Ker 6

好吧...只需使用 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);
Run Code Online (Sandbox Code Playgroud)