Jim*_*Jim 1 android google-maps latitude-longitude coordinates google-maps-api-3
我有一系列物品,其中一些可能具有相同的坐标。
因此,它们在 Google 地图中显示为 1 个标记,因为标记是一个一个地绘制的。
为了解决这个问题,我尝试将这些标记“移动”几米,以便标记不会发生碰撞。
我想将它们移动到距其位置 5 米的地方。
我做了以下另一个SO答案:
double newLat = item.getLatitude() + (Math.random() - .005) / 15000;
double newLon = item.getLongitude() + (Math.random() - .005) / 15000;
Run Code Online (Sandbox Code Playgroud)
问题是,这会稍微移动物品,但似乎有些物品移动了 4m,另一些则移动了 3m,我希望尽可能确保我的移动距离在 4-6 米(最小/最大)之间,我该如何更改我的
公式去做这个?
我认为最好的选择可能是使用Google Maps Android API Utility LibrarySphericalUtil. computeOffset中的方法:
计算偏移量
Run Code Online (Sandbox Code Playgroud)public static LatLng computeOffset(LatLng from, double distance, double heading)返回从指定航向中的原点移动一定距离后得到的 LatLng(以从北顺时针方向的角度表示)。
参数:
from - 开始的 LatLng。
距离- 行驶的距离。
航向- 从北开始顺时针方向的航向(以度为单位)。
在您的情况下,您可以将 参数设置distance为 5 米,并将heading参数随机化为 0 到 360 度之间的值:
Random r = new Random();
int randomHeading = r.nextInt(360);
LatLng newLatLng = SphericalUtil.computeOffset(oldLatLng, 5, randomHeading);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2408 次 |
| 最近记录: |