如何根据中心和半径获取Google地图中圆圈的LatLngBounds?

mel*_*dre 5 geometry android google-maps coordinates android-studio

如何获得具有给定中心和半径的圆的东北和西南坐标?我找不到任何解决方案.目前,Circle对象没有以前的getLatLngBounds()和getBounds()方法.

ant*_*nio 6

您可以使用SphericalUtil.computeOffset从方法 谷歌地图API的Android实用工具库.要使用它,您需要具有以下依赖关系build.gradle:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以计算您的圆圈的东北和西南坐标:

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);
Run Code Online (Sandbox Code Playgroud)

  • 45 是朝向东北的度数(0 表示北),225 是朝向西南的度数(180 度即南加 45 度) (2认同)