如何在Android API V2中显示Google地图的特定区域/区域

3
如何在Android API V2中仅显示Google地图的特定区域?该区域内必须包含所有功能,例如缩放、拖动等。所有其他区域必须被裁剪或隐藏。这是否可能?我正在使用Eclipse,请帮助我。

请阅读这个链接:http://stackoverflow.com/help/how-to-ask,并根据其中的内容来构建你的问题!是的,这是可能的。 - el solo lobo
2个回答

3

这个技巧对我很有用

  @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    //get latlong for corners for specified place
    LatLng one = new LatLng(27.700769, 85.300140);
    LatLng two = new LatLng(27.800769, 85.400140);

    LatLngBounds.Builder builder = new LatLngBounds.Builder();

    //add them to builder
    builder.include(one);
    builder.include(two);

    LatLngBounds bounds = builder.build();

    //get width and height to current display screen
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;

    // 20% padding
    int padding = (int) (width * 0.20);

    //set latlong bounds
    mMap.setLatLngBoundsForCameraTarget(bounds);

    //move camera to fill the bound to screen
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));

    //set zoom to level to current so that you won't be able to zoom out viz. move outside bounds
    mMap.setMinZoomPreference(mMap.getCameraPosition().zoom);
}

0

如果您想要显示特定的区域或地区,那么可以使用多边形。

多边形对象与折线对象类似,它们由一系列有序的坐标组成。但是,多边形不同于折线,它们被设计为在封闭的环路内定义区域并填充其内部。

您可以通过与添加折线相同的方式向地图添加多边形。首先创建一个PolygonOptions对象,并添加一些点。这些点将形成多边形的轮廓。然后通过调用GoogleMap.addPolygon(PolygonOptions)将多边形添加到地图中,该方法将返回一个Polygon对象。

访问页面了解如何使用多边形。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接