安卓:Skobbler,如何限制在一个区域地图视图? [英] Android: Skobbler, how to limit map view in an area?
问题描述
我是新不仅对Skobbler也为地图。在这个时候,我试图创造一个MAPP应用程序,只显示一个区域。
I'm new not only on Skobbler but also for Map. At this time, i'm trying to create a mapp app that show only an area.
和,我想要是:
- 用户不能迁出该区域的。
- 请不要加载该区域以外的任何东西(头衔,..)。
- 用户可以查看和只能放大。
我试过约束象下面,但它不工作:
I tried with bound like below but it not work:
SKBoundingBox boundingBox = new SKBoundingBox(47.087426, 8.257230, 46.874277, 8.637632);
mapView.fitBoundingBox(boundingBox, 0, 0);
您能否给一些提示,请?
Could you give some hint, please?
推荐答案
目前的SDK不支持限制图表操作的边界盒。
Currently the SDK does not support limiting map operations to a bounding box.
作为解决办法,每当地图区域就是在屏幕上的变化可见(如平移,缩放或旋转的结果),它去定义的边界框之外,地图将切换到最后一个可见区域,这是内部的该边界框:
As a workaround, whenever the map region that is visible on the screen changes (as a result of panning, zooming or rotation) and it goes outside the defined bounding box the map will switch back to the last visible region that was inside that bounding box:
public class MapActivity extends Activity implements SKMapSurfaceListener, ... {
...
// the box inside which map operations are allowed
private SKBoundingBox box = new SKBoundingBox(47.087426, 8.257230, 46.874277, 8.637632);
// last region that was visible on the screen and was inside the box
private SKCoordinateRegion lastValidRegion = null;
...
@Override
public void onSurfaceCreated(SKMapViewHolder mapHolder) {
...
// position the map somewhere inside your box
mapView.centerMapOnPosition(new SKCoordinate(8.304354, 47.050253));
}
...
// checks if a given region is inside the bounding box
private boolean isInBoundingBox(SKCoordinateRegion newRegion) {
SKBoundingBox newBoundingBox = mapView.getBoundingBoxForRegion(newRegion);
if (newBoundingBox.getTopLeftLatitude() > box.getTopLeftLatitude() || newBoundingBox.getBottomRightLatitude() < box.getBottomRightLatitude() ||
newBoundingBox.getTopLeftLongitude() < box.getTopLeftLongitude() || newBoundingBox.getBottomRightLongitude() > box.getBottomRightLongitude()) {
return false;
}
return true;
}
@Override
public void onMapRegionChanged(SKCoordinateRegion mapRegion) {
boolean inBoundingBox = isInBoundingBox(mapRegion);
if (inBoundingBox) {
// if mapRegion is valid save it
if (lastValidRegion == null) {
lastValidRegion = new SKCoordinateRegion(mapRegion.getCenter(), mapRegion.getZoomLevel());
} else {
lastValidRegion.setCenter(mapRegion.getCenter());
lastValidRegion.setZoomLevel(mapRegion.getZoomLevel());
}
} else {
// if mapRegion is invalid reposition the map inside the bounding box
if (lastValidRegion != null) {
mapView.changeMapVisibleRegion(lastValidRegion, false);
}
}
}
}
此外,如果需要的话,限制也可以应用于放大使用SKMapSettings.setZoomLimits水平(...)方法
Also, if needed, limits can also be applied to zoom levels using the SKMapSettings.setZoomLimits(...) method.
这篇关于安卓:Skobbler,如何限制在一个区域地图视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!