使用Mapsforge绘制OverlayWays

Jon*_*itu 1 maps android

我正在尝试使用Mapsforge在我的Android应用中绘制一种简单的方法,一种路线.我已经按照一个例子创建了单点OverlayItems.但是当我尝试画一条路线时,我在地图上看不到任何东西.有谁能够帮我?这是我的简单代码:

    Paint wayPaint = new Paint();
    wayPaint.setColor(color.Chocolate);
    ArrayWayOverlay wayOverlay = new ArrayWayOverlay(wayPaint,wayPaint);
    GeoPoint gp1 = new GeoPoint(41.38, 2.15);
    GeoPoint gp2 = new GeoPoint(41.39, 2.15);
    GeoPoint gp3 = new GeoPoint(41.40, 2.15);
    GeoPoint gp4 = new GeoPoint(41.41, 2.15);
    OverlayWay way = new OverlayWay(new GeoPoint[][] { { gp1, gp2, gp3, gp4 } });
    wayOverlay.addWay(way);
    mapView.getOverlays().add(wayOverlay);
Run Code Online (Sandbox Code Playgroud)

我不知道是否必须在某处放置标记......

Rak*_*ari 11

OverlayWayAPI已被弃用的v-0.4.0.由于我很难找到在地图上绘制叠加层的新方法,我想我会在这里发布.Mapsforge现在添加了以下类型的叠加层:

 1. Circle
 2. FixedPixelCircle
 3. Marker
 4. Polygon
 5. Polyline
Run Code Online (Sandbox Code Playgroud)

所有新类都扩展了Layer类,使其易于实现.您实例化所需的对象并将其添加MapView到此类似的对象中.

// instantiating the paint object 
Paint paint = AndroidGraphicFactory.INSTANCE.createPaint();
paint.setColor(color);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(style);

// instantiating the polyline object
Polyline polyline = new Polyline(paint, AndroidGraphicFactory.INSTANCE);

// set lat lng for the polyline
List<LatLong> coordinateList = polyline.getLatLongs();
coordinateList.add(latlng1);
coordinateList.add(latlng2);
coordinateList.add(latlng3);
coordinateList.add(latlng4);
coordinateList.add(latlng5);

// adding the layer to the mapview
mapView.getLayerManager().getLayers().add(polyline);
Run Code Online (Sandbox Code Playgroud)

还有一个mapsforge示例链接可用.