【问题标题】:Android - Get polyline as imageAndroid - 获取折线作为图像
【发布时间】:2017-07-01 10:52:23
【问题描述】:

如何将已经在谷歌地图上绘制的折线作为图像? 只有折线,没有地图布局。

我在 Google 地图上绘制了多段线,我想将多段线作为图像获取。所以它只显示红线,没有任何地图

https://i.stack.imgur.com/vUqS3.png

【问题讨论】:

  • 你解决了吗?我需要完全相同的东西
  • @Favolas 是的。检查我的答案。抱歉回复晚了
  • 我也设法实现了这一点。这是我的approach

标签: java android google-maps polyline


【解决方案1】:

我设法通过将坐标更改为点来解决这个问题

private Bitmap createPolylineBitmap() {
    Bitmap bitmap = Bitmap.createBitmap(mapFragment.getView().getWidth(), mapFragment.getView().getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setColor(ContextCompat.getColor(this, R.color.purple));
    paint.setStrokeWidth(10);
    paint.setDither(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setAntiAlias(true);

    for (int i = 0; i < coordinates.size(); i++) {
        LatLng latLng1 = new LatLng(coordinates.get(i).latitude, coordinates.get(i).longitude);
        LatLng latLng2 = new LatLng(coordinates.get(i + 1).latitude, coordinatest.get(i + 1).longitude);
        canvas.drawLine((LatLngToPoint(latLng1).x), ((LatLngToPoint(latLng1).y)), (LatLngToPoint(latLng2).x), (LatLngToPoint(latLng2).y), paint);
    }

    return bitmap;
}

private Point LatLngToPoint(LatLng coordinate) {
    Projection projection = googleMap.getProjection();

    return projection.toScreenLocation(coordinate);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多