Java (Android)使用地图标记创建边界框,并在Google map V2中获取其宽度
我使用以下代码在Android中缩放并显示Google地图上的所有标记。它运行良好:Java (Android)使用地图标记创建边界框,并在Google map V2中获取其宽度,java,android,google-maps,google-maps-android-api-2,Java,Android,Google Maps,Google Maps Android Api 2,我使用以下代码在Android中缩放并显示Google地图上的所有标记。它运行良好: LatLngBounds.Builder builder = new LatLngBounds.Builder(); //the include method will calculate the min and max bound. builder.include(marker1.getPosition()); builder.include(marker2.getPosition()); builder.
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//the include method will calculate the min and max bound.
builder.include(marker1.getPosition());
builder.include(marker2.getPosition());
builder.include(marker3.getPosition());
builder.include(marker4.getPosition());
LatLngBounds bounds = builder.build();
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
int padding = (int) (width * 0.10); // offset from edges of the map 10% of screen
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);
mMap.animateCamera(cu);
但我想做的是映射一个边界框中的所有标记,然后得到该框的宽度。我该怎么做?您需要使用
边界.东北
和边界.西南
坐标
并使用Location.distanceBetween()
方法或:
您需要使用
bounds.Northwest
和bounds.southwest
坐标
并使用Location.distanceBetween()
方法或:
修改此行
LatLngBounds bounds bounds=builder.build()代码>到这个
LatLngBounds bounds = googleMap.getProjection()
.getVisibleRegion().latLngBounds;
修改此行LatLngBounds bounds bounds=builder.build()代码>到这个
LatLngBounds bounds = googleMap.getProjection()
.getVisibleRegion().latLngBounds;
@与您的代码示例一样快速:builder.include(marker1.getPosition())代码>。。。然后LatLngBounds bounds bounds=builder.build()您可以使用bounds.northwest
和bounds.soutwest
@Speedy,如代码示例中所示:builder.include(marker1.getPosition())代码>。。。然后LatLngBounds bounds bounds=builder.build()
并且您可以使用bounds.Northwest
和bounds.southwest
。