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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
回答2:
Essentially copying and pasting antonio's answer:
public static LatLngBounds getLatLngBoundsFromCircle(Circle circle){
if(circle != null){
return new LatLngBounds.Builder()
.include(SphericalUtil.computeOffset(circle.getCenter(), circle.getRadius() * Math.sqrt(2), 45))
.include(SphericalUtil.computeOffset(circle.getCenter(), circle.getRadius() * Math.sqrt(2), 225))
.build();
}
return null;
}