移動到以某區域為中心的畫面 === * method 1 padding 沒有效果,改用第二種方法 ```java= LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (LatLng latlng: points) { builder.include(latlng); } LatLngBounds BANGLADESH = builder.build(); int padding = 15; // offset from edges of the map in pixels CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(BANGLADESH, padding); // 畫面移動至以圍籬為中心 mMap.moveCamera(cameraUpdate); ``` * method 2 ```java= /** * 找一多邊形的涵蓋區域, ex: 以下為一五邊形, 找到最北邊點與最東邊點的交界, 反之亦然 * * ● — — — — ┼ (north, east) * ● │ * │ ● │ * │ ● * ┼ — — ● * (south, west) */ LatLngBounds australiaBounds = new LatLngBounds( new LatLng(-44, 113), // SW bounds new LatLng(-10, 154) // NE bounds ); map.moveCamera(CameraUpdateFactory.newLatLngZoom(australiaBounds.getCenter(), 10)); ``` ## Ref. [How to find LatLng bound for an area in google maps?](https://stackoverflow.com/questions/61527656/how-to-find-latlng-bound-for-an-area-in-google-maps) [將地圖置於某區域的中心位置](https://developers.google.com/maps/documentation/android-sdk/views?hl=zh-tw#centering_the_map_within_an_area) [Android map v2 zoom to show all the markers](https://stackoverflow.com/questions/14828217/android-map-v2-zoom-to-show-all-the-markers) ###### tags: `GMS`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up