Android - Get polyline as image

有些话、适合烂在心里 提交于 2019-12-24 07:38:30

问题


How do you get polyline that already plotted on Google Map as image? Only the polyline, without the map layout.

I have plotted the polyline on the Google Map and I want to get the polyline as an image. So it only show the red line without any map

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


回答1:


I manage to solve this by changing the coordinate to point

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


来源:https://stackoverflow.com/questions/42204301/android-get-polyline-as-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!