Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在Google map V2中在多边形上绘制网格_Android_Google Maps_Maps_Overlay_Polygon - Fatal编程技术网

Android 在Google map V2中在多边形上绘制网格

Android 在Google map V2中在多边形上绘制网格,android,google-maps,maps,overlay,polygon,Android,Google Maps,Maps,Overlay,Polygon,我已经在Google map v2上制作了一个多边形,现在我想在该多边形上添加一个网格,如参考图像所示,该网格应该重新调整大小,并且网格的部分应该是可选的 我对此一无所知,所以请帮忙。 到目前为止我一直在尝试,但仍然没有任何结果。 谢谢你的帮助 参考图像: 不确定谷歌地图,但使用osmdroid时,您应该使用并实现自定义多边形: public class GridPolygon extends Polygon { private BitmapShader bitmapShader;

我已经在Google map v2上制作了一个多边形,现在我想在该多边形上添加一个网格,如参考图像所示,该网格应该重新调整大小,并且网格的部分应该是可选的

我对此一无所知,所以请帮忙。 到目前为止我一直在尝试,但仍然没有任何结果。 谢谢你的帮助

参考图像:


不确定谷歌地图,但使用osmdroid时,您应该使用并实现自定义多边形:

public class GridPolygon extends Polygon {

    private BitmapShader bitmapShader;
    private IGeoPoint lastCenterGeoPoint;
    private int xOffset = 0;
    private int yOffset = 0;

    public GridPolygon(Context ctx) {
        super(ctx);
    }

    public void setPatternBMP(@NonNull final Bitmap patternBMP) {
        bitmapShader = new BitmapShader(patternBMP, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        mFillPaint.setShader(bitmapShader);
    }

    protected void recalculateMatrix(@NonNull final MapView mapView) {
        //final int mapSize = TileSystem.MapSize(mapView.getZoomLevel());

        final Projection projection = mapView.getProjection();
        final IGeoPoint geoPoint = mapView.getMapCenter();
        if (lastCenterGeoPoint == null) lastCenterGeoPoint = geoPoint;

        final Point point = projection.toPixels(geoPoint, null);
        final Point lastCenterPoint = projection.toPixels(lastCenterGeoPoint, null);

        xOffset += lastCenterPoint.x - point.x;
        yOffset += lastCenterPoint.y - point.y;

        xOffset %= 100; // 100 is pixel size of shader image
        yOffset %= 100;

        final Matrix matrix = new Matrix();
        matrix.reset();
        matrix.setScale(1,1);
        matrix.preTranslate(xOffset, yOffset);
        //matrix.setTranslate(xOffset, yOffset);
        bitmapShader.setLocalMatrix(matrix);

        mFillPaint.setShader(bitmapShader);

        lastCenterGeoPoint = geoPoint;
    }

    @Override
    protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
        recalculateMatrix(mapView);
        super.draw(canvas, mapView, shadow);
    }
}


.

你好,你做了吗?那形状看起来很熟悉!;)