如何在google地图中找到一个区域的LatLng绑定?

问题描述 投票:0回答:1

google maps 我想把我的相机固定在一个特定的国家。我不需要整个世界 Mercator 投影。所以我需要设置 LatLngBounds 在我的谷歌地图。我怎样才能找到 LatLngBounds 我的代码是这样的,但它没有设定 LatLngBounds 作为我的期望集的限制在右侧。

         LatLng v1= new LatLng(24.044982389517603,89.75482430309057);
         LatLng v2 = new LatLng(22.309956868003045,91.20187237858772);
        LatLngBounds BANGLADESH = new LatLngBounds(
                v2,v1
        );
        mMap.setLatLngBoundsForCameraTarget(BANGLADESH);

enter image description here

android google-maps google-maps-android-api-2
1个回答
0
投票

你可以得到国家边界一次从 openstreetmap.org 如同 这个 条款 Pēteris Ņikiforovs. 或以 http:/polygons.openstreetmap.frget_poly.py?id=184640&params=0。 并将其添加为多边形点,找到 LatLngBounds 像你这样做。

...
Builder builder = new LatLngBounds.Builder(); 
for(int i = 0 ; i < N_POINTS; i++) {          
    builder.include(new LatLng(lat, lng));
}
LatLngBounds BANGLADESH = new LatLngBounds = builder.build();

int padding = 15; // offset from edges of the map in pixels
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(BANGLADESH, padding);

mMap.moveCamera(cameraUpdate );
...
© www.soinside.com 2019 - 2024. All rights reserved.