简体   繁体   中英

Android Google Map v2 draw static grids

I'm trying to draw grids on map only when zoom level is 18. I created grids with below code successfully. But i have one problem when I move map, new grids are created and there position change. You can see that in screenshot in right image I swiped map to left and grid lines are not same. I want fixed grids drawn. Code posted below images. I'm calling below code from onCameraChange listener of GoogleMap. 在此处输入图片说明

double squareSize = 5.0d; //5.0d == 50feet
final double LONGITUDE_180 = 180.0d;
final double LATITUDE_90 = 90.0d;
final double PI = 3.141592653589793d;

Code removed its confidential.

drawPolyline function to draw single line

private void drawPolyline(LatLng latLng, LatLng latLng2) {
        PolylineOptions polylineOptions = new PolylineOptions();
        polylineOptions.add(latLng, latLng2);
        polylineOptions.color(Color.argb(50, 0, 0, 100));
        polylineOptions.width(3.5f);
        polylineOptions.visible(true);
        polylineOptions.geodesic(true);
        Polyline polyline = googleMap.addPolyline(polylineOptions);

        this.polylines.add(polyline);
    }
double squareSize = 5.0d; //5.0d == 50feet

That is not square Size change it to.

double squareSize = 1.0d;

Then it will work fine but grid size will 3 meter as in what3words. To make it 15 meters which is close to 50 feet divide 1546.0d and 37104.0d with 5.

37104.0d is equal 1546.0d * 24 .

Better to extract all these values in variable and use them as.

double var1 = 1546.0d / 5;   // replace with value 1546.0
double var2 = var1 * 24; // replace with value 37104.0d

Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM