Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the LatLngBounds of a Circle in Google maps given its center and radius?

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.

like image 597
melisandre Avatar asked May 18 '16 15:05

melisandre


People also ask

Can Google Maps draw a circle of given radius?

How Do I Draw a Radius on Google Maps? Google Maps does not support the radius functionality, which means that you can't determine the radius around a given location. But you can measure the distance between two or more points.

How do I use the radius tool on Google Maps?

Click on the map and create a popup marker to select the point. From there, opt for the “Draw Radius.” Choose the proximity distance from the given address found within the radius options in the software.


1 Answers

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);
like image 106
antonio Avatar answered Oct 13 '22 02:10

antonio