【问题标题】:How to restrict android google map to a city?如何将安卓谷歌地图限制在一个城市?
【发布时间】:2017-08-17 07:30:36
【问题描述】:

如何将 android 谷歌地图限制为一个城市?
我目前正在关注显示谷歌地图的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

我只想展示一个城市。有办法吗?

【问题讨论】:

标签: android google-maps city


【解决方案1】:

使用官方文档 restrict the user's panning to a given area

限制用户。

更新 Play 服务的依赖项:

dependencies {
    compile 'com.google.android.gms:play-services:9.6.1'
}

【讨论】:

  • 嘿,谢谢回答,但我希望用户不会去其他位置,例如在地图上看到阿德莱德,不能移动到其他地方,只需放大和缩小阿德莱德。
【解决方案2】:
private static final LatLngBounds DUBAI_BOUNDS = new LatLngBounds(new LatLng(24.5908366068, 54.84375),
            new LatLng(25.3303729706, 55.6835174561));


map.setLatLngBoundsForCameraTarget(DUBAI_BOUNDS);

【讨论】:

  • 你是怎么得到西南坐标的?
【解决方案3】:

你可以在thismadhu sudhan的答案disable scroll gesture点赞:

mGoogleMap.getUiSettings().setScrollGesturesEnabled(false);

其中mGoogleMap - GoogleMap 类的对象。

【讨论】:

    猜你喜欢
    • 2016-01-17
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多