【问题标题】:How can draw a line(Polyline ) in Android studio in OSM (open map street)?如何在 OSM(打开地图街道)的 Android Studio 中绘制一条线(Polyline)?
【发布时间】:2018-06-27 16:59:04
【问题描述】:

我想在 OSM 中的 2 点之间画一条线,但我找不到任何对我有帮助的东西。类似于 googlemap 中的折线。

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);
}
}

【问题讨论】:

    标签: android openstreetmap osmdroid


    【解决方案1】:

    嗯...只需使用 osmdroid 折线。

        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);
    

    【讨论】:

      【解决方案2】:

      我将此代码放在 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。

      【讨论】:

      • 如何删除折线上的最后一个点?在折线类中,我们有 addpoint 方法,但在 osmdroid 折线类上没有删除点方法..
      猜你喜欢
      • 2014-08-10
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      相关资源
      最近更新 更多