Android Google Maps LatLng to Bounds by Radius

July 22, 2018
import com.google.maps.android.SphericalUtil

inline fun LatLng.toBounds(radius: Double): LatLngBounds {
    // radius is in meter
    val southwest = SphericalUtil.computeOffset(this, radius * Math.sqrt(2.0), 225.0)
    val northeast = SphericalUtil.computeOffset(this, radius * Math.sqrt(2.0), 45.0)
    return LatLngBounds(southwest, northeast)
}

NOTE: Google Maps Android API Utility Library is used.

build.gradle (Module)

dependencies {
    implementation 'com.google.maps.android:android-maps-utils:0.5'
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.