How to get LatLngBounds circle in google maps, given its center and radius?

How can I get the coordinates of the North and Southwest circles with a given center and radius? I can not find a solution anywhere. Currently, the Circle object does not have the getLatLngBounds () and getBounds () methods, unlike the previous ones.

+5
source share
2 answers

You can use the SphericalUtil.computeOffset method from the Google API API API for Android . To use it, you need the following relation to your build.gradle :

 dependencies { compile 'com.google.maps.android:android-maps-utils:0.4+' } 

Then you can calculate the north-east and south-west coordinates of your circle:

 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); 
+6
source

Essentially copying and pasting an Antonio response:

  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; } 
+1
source

All Articles