Get Radius Of Visible Map in Android

后端 未结 5 389
温柔的废话
温柔的废话 2020-12-03 11:11

Is there any possible way of finding radius of the visible map from the middle point?

\"Google

I

5条回答
  •  一生所求
    2020-12-03 11:30

    For the Kotlin users, call this function from setOnCameraIdleListener

    private fun getMapVisibleRadius(): Double {
        val visibleRegion: VisibleRegion? = mMap?.projection?.visibleRegion
    
        val distanceWidth = FloatArray(1)
        val distanceHeight = FloatArray(1)
    
        val farRight: LatLng? = visibleRegion?.farRight
        val farLeft: LatLng? = visibleRegion?.farLeft
        val nearRight: LatLng? = visibleRegion?.nearRight
        val nearLeft: LatLng? = visibleRegion?.nearLeft
    
        Location.distanceBetween((farLeft!!.latitude + nearLeft!!.latitude) / 2,
                farLeft.longitude,
                (farRight!!.latitude + nearRight!!.latitude) / 2,
                farRight.longitude, distanceWidth)
    
        Location.distanceBetween(farRight.latitude,
                (farRight.longitude + farLeft.longitude) / 2,
                nearRight.latitude,
                (nearRight.longitude + nearLeft.longitude) / 2,
                distanceHeight)
    
        return Math.sqrt((Math.pow(distanceWidth[0].toString().toDouble(), 2.0))
                + Math.pow(distanceHeight[0].toString().toDouble(), 2.0)) / 2
    }
    

提交回复
热议问题