Setting max zoom level in google maps android api v2

后端 未结 16 2225
无人共我
无人共我 2020-12-02 17:14

I\'m currently working on developing apps by using Google maps android API v2. My code is as follows. Suppose map has several markers and zoom up to show all markers in disp

16条回答
  •  萌比男神i
    2020-12-02 17:36

    @kasimir's approach sets a minimum number of degrees in either the latitude or longitude, and felt a little hard to read. So I tweaked it to just set a minimum on the latitude, which I felt like was a bit more readable:

    private LatLngBounds adjustBoundsForMinimumLatitudeDegrees(LatLngBounds bounds, double minLatitudeDegrees) {
        LatLng sw = bounds.southwest;
        LatLng ne = bounds.northeast;
        double visibleLatitudeDegrees = Math.abs(sw.latitude - ne.latitude);
    
        if (visibleLatitudeDegrees < minLatitudeDegrees) {
            LatLng center = bounds.getCenter();
            sw = new LatLng(center.latitude - (minLatitudeDegrees / 2), sw.longitude);
            ne = new LatLng(center.latitude + (minLatitudeDegrees / 2), ne.longitude);
            bounds = new LatLngBounds(sw, ne);
        }
    
        return bounds;
    }
    

提交回复
热议问题