Java (Android)使用地图标记创建边界框,并在Google map V2中获取其宽度

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.

我使用以下代码在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.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