在给定 4 个点的坐标的情况下,在谷歌地图 API 上创建一个正方形网格



我是android工作室的新手,我正在尝试构建一个基于地图的应用程序。该应用程序的功能之一是根据地图上 4 个点的(纬度、经度(在地图上构建一个方形网格。在对这个主题的研究之后,我发现的大多数答案 在整个地图上创建一个不需要的方形网格。对此的任何帮助都深表感谢。

链接到与此类似的问题:

在安卓中使用谷歌地图 API 添加静态方形网格

使用折线在谷歌地图上绘制矩形。

示例代码:

// Instantiates a new Polyline object and adds points to define a rectangle
PolylineOptions rectOptions = new PolylineOptions()
.add(new LatLng(37.35, -122.0))
.add(new LatLng(37.45, -122.0))  // North of the previous point, but at the same longitude
.add(new LatLng(37.45, -122.2))  // Same latitude, and 30km to the west
.add(new LatLng(37.35, -122.2))  // Same longitude, and 16km to the south
.add(new LatLng(37.35, -122.0)); // Closes the polyline.
// Get back the mutable Polyline
Polyline polyline = myMap.addPolyline(rectOptions);

检查此链接以绘制不同的形状。

最新更新