首页 > 解决方案 > 如何在谷歌地图中绑定校园地图?

问题描述

我是这种编程语言的新手,所以我复制并粘贴了在网上找到的代码,然后我找到并尝试在限制某个区域时使用这些代码,它可以工作:

private GoogleMap mMap;
// Create a LatLngBounds that includes the city of Adelaide in Australia.
private LatLngBounds ADELAIDE = new LatLngBounds(
new LatLng(-35.0, 138.58), new LatLng(-34.9, 138.61));
// Constrain the camera target to the Adelaide bounds.
mMap.setLatLngBoundsForCameraTarget(ADELAIDE);

但是当我使用我的校园坐标将其更改为这样时:

private LatLngBounds CPUBounds = new LatLngBounds(
new LatLng(10.732581, 122.548413), new LatLng(10.730052, 122.549958));

我的应用程序突然停止工作。我应该怎么办?

标签: androidgoogle-maps

解决方案


尝试粘贴 Logcat 以查看错误

从如果你想显示具体位置试试下面的代码

要在特定区域上移动相机位置,请使用此功能,

mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 
                           zoomWidth, 
                           zoomHeight, 
                           zoomPadding));

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(10.732581, 122.548413), 
                           zoomHeight));

如果您想在区域上添加标记,请使用

mMap.addMarker(new MarkerOptions()
                       .position(new LatLng(10.732581, 122.548413))
                       .title("campus name"));

禁用拖动使用 mMap.getUiSettings().setScrollGesturesEnabled(false);

但它不会通过触摸地图来禁用地图缩放。为此使用以下代码 googleMap.getUiSettings().setZoomGesturesEnabled(false);


推荐阅读