Get Radius Of Visible Map in Android

后端 未结 5 400
温柔的废话
温柔的废话 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:13

    Full area, even corners!

    I don't see other answers cover the entire map area;

    see image below, to test it I drew a circle overlay to see the bounds of the calculated radius, it does not cover entire map area.

    my modification is quite simple, I've used Pythagorean theorem to find the suitable radius to contain the map "rectangle".



    private double getMapVisibleRadius() {
        VisibleRegion visibleRegion = googleMap.getProjection().getVisibleRegion();
    
        float[] distanceWidth = new float[1];
        float[] distanceHeight = new float[1];
    
        LatLng farRight = visibleRegion.farRight;
        LatLng farLeft = visibleRegion.farLeft;
        LatLng nearRight = visibleRegion.nearRight;
        LatLng nearLeft = 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
        );
    
        double radiusInMeters = Math.sqrt(Math.pow(distanceWidth[0], 2) + Math.pow(distanceHeight[0], 2)) / 2;
        return radiusInMeters;
    }
    

提交回复
热议问题