Create RectangularBounds Based on Latlng With Radius

Nov 24, 2019
// in meterval radius = 30.0// optional: to get distance to circle radius, not the edgeval distance = radius * sqrt(2.0)val center = LatLng(3.1412, 101.68653)val ne = SphericalUtil.computeOffset(center, distance, 45.0)val sw = SphericalUtil.computeOffset(center, distance, 225.0)val bounds = RectangularBounds.newInstance(sw, ne)

Dependencies

dependencies {
    implementation 'com.google.maps.android:android-maps-utils:0.5'
}

Kotlin extensions

fun LatLng.toBounds(distance: Double): RectangularBounds {    val center = this    val ne = SphericalUtil.computeOffset(center, distance, 45.0)    val sw = SphericalUtil.computeOffset(center, distance, 225.0)    return RectangularBounds.newInstance(sw, ne)}

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.