问题描述
如何获得具有给定中心和半径的圆的东北和西南坐标?我找不到任何解决方案。目前,与之前不同,Circle对象没有getLatLngBounds()和getBounds()方法。
How can I get the Northeast and Southwest coordinates of a Circle with a given center and radius? I can't find any solution anywhere. Currently, the Circle object doesn't have getLatLngBounds() nor getBounds() methods unlike before.
推荐答案
您可以使用$ b中的 SphericalUtil.computeOffset
方法$ b 。要使用它,您需要对 build.gradle
执行以下依赖项:
You can use the SphericalUtil.computeOffset
method from theGoogle Maps Android API Utility Library. To use it you need to the following dependency to your build.gradle
:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
然后,您可以计算您的圈子的东北和西南坐标:
Then, you can calculate the northeast and southwest coordinates of your circle doing:
double radius = 104.52;
LatLng center = new LatLng(40.22861, -3.95567);
LatLng targetNorthEast = SphericalUtil.computeOffset(center, radius * Math.sqrt(2), 45);
LatLng targetSouthWest = SphericalUtil.computeOffset(center, radius * Math.sqrt(2), 225);
这篇关于如何根据Google地图的中心和半径获取圆圈的LatLngBounds?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!