简体   繁体   English

Android Google Map v2 绘制静态网格

[英]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.仅当缩放级别为 18 时,我才尝试在地图上绘制网格。我使用以下代码成功创建了网格。 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.我正在从 GoogleMap 的 onCameraChange 侦听器调用以下代码。 在此处输入图片说明

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 drawPolyline 函数绘制单条线

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.然后它会正常工作,但网格大小将像 what3words 一样为 3 米。 To make it 15 meters which is close to 50 feet divide 1546.0d and 37104.0d with 5.为了使它成为接近 50 英尺的 15 米,将1546.0d37104.0d除以5。

37104.0d is equal 1546.0d * 24 . 37104.0d等于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.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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