Android - 获取折线作为图像

Android - Get polyline as image

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

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

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

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

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