1

我正在尝试使用 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);

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

4

2 回答 2

10

OverlayWayapi 已被弃用v-0.4.0。因为我很难找到在地图上绘制叠加层的新方法,所以我想我把这个贴在这里。Mapsforge现在添加了以下类型的叠加层:

 1. Circle
 2. FixedPixelCircle
 3. Marker
 4. Polygon
 5. Polyline

所有新类都扩展了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);

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

于 2014-09-11T06:18:35.597 回答
4

尝试设置 wayPaint Style 和笔画宽度,如下所示:

Paint wayPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
wayPaint.setStyle(Paint.Style.STROKE);
wayPaint.setColor(Color.BLUE);
wayPaint.setAlpha(192);
wayPaint.setStrokeWidth(6);
wayDefaultPaintFill.setStrokeJoin(Paint.Join.MITER);

ArrayWayOverlay wayOverlay = new ArrayWayOverlay(wayPaint,wayPaint);
//your points
OverlayWay way = new OverlayWay(new GeoPoint[][] { {geoPoint1,geoPoint2,... } });
wayOverlay.addWay(way);
mapView.Overlays().add(wayOverlay);

希望这可以帮助!

于 2013-08-02T10:57:23.193 回答