给定圆心和半径,如何在谷歌地图中获得圆的纬度边界?

问题描述:

如何获得给定中心和半径的圆的东北和西南坐标?我在任何地方都找不到任何解决方案.目前,与以前不同,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.

您可以使用 SphericalUtil.computeOffset 方法从Google Maps Android API 实用程序库.要使用它,您需要对 build.gradle 有以下依赖:

You can use the SphericalUtil.computeOffset method from the Google 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);