Set a max zoom level on LatLngBounds builder

前端 未结 10 623
慢半拍i
慢半拍i 2020-12-13 00:57

I haven\'t found an answer in my search, there are a few answers on SO but they didn\'t work for me.

I have 2 markers on the map and I am using LatLngBounds builder

10条回答
  •  萌比男神i
    2020-12-13 01:30

    Here is a much shorter version based on user2808624's answer.

            LatLngBounds bounds = builder.build();
            LatLng center = bounds.getCenter();
            builder.include(new LatLng(center.latitude-0.001f,center.longitude-0.001f));
            builder.include(new LatLng(center.latitude+0.001f,center.longitude+0.001f));
            bounds = builder.build();
    

    Its a bit sloppy, but you can use 0.001 to zoom no less than a city block, 0.01 for no less than a city view. Only advantage is its only 4 extra lines of code.

提交回复
热议问题