android - 如何在谷歌地图中绑定校园地图?
问题描述
我是这种编程语言的新手,所以我复制并粘贴了在网上找到的代码,然后我找到并尝试在限制某个区域时使用这些代码,它可以工作:
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));
我的应用程序突然停止工作。我应该怎么办?
解决方案
尝试粘贴 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);
推荐阅读
- c# - Windows Server 2019 上的错误 Office.Interop.Word
- html - 为什么 CSS 自定义标签会导致 Angular 错误
- c# - 错误某些服务无法构建(验证服务描述符时出错)
- python - Python:遍历 ndarray 并保存图像
- xml - 如何检查xml文件中节点的值是否总是使用xsl/xslt从另一个修复节点的值中获取?
- button - Bootstrap 5 响应式按钮放置。如何?
- python - Poppler 安装 Anaconda 问题
- bash - Standford moss - 文本扩展不能作为输入
- amazon-web-services - Sagemaker 推理管道 - 自定义容器无法通过 ping 检查,但未发送 ping 请求?
- memory-management - msync 性能是否取决于所提供范围的大小?