java - Java Android Google 地图更改缩放控件位置并将相机设置为标记
问题描述
我希望缩放控件位于中间的最顶部,我试图做这样的事情,但它不起作用:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().
findFragmentById(R.id.map);
View mapView = mapFragment.getView();
View zoom_in_button = mapView.findViewWithTag("GoogleMapZoomInButton");
RelativeLayout.LayoutParams location_layout = (RelativeLayout.LayoutParams) zoom_in_button.getLayoutParams();
location_layout.addRule(RelativeLayout.CENTER_HORIZONTAL, 0);
我还需要得到这个:将视图居中,使标记位于左下角
我这样做了,但它不起作用。
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentPGO.getLatitude(), currentPGO.getLongitude()), 16));
解决方案
隐藏谷歌地图的默认缩放按钮
mMap.uiSettings.isZoomControlsEnabled = false
为放大和缩小创建 ImageView/Button 小部件(在顶部中心或任何您喜欢的位置对齐,在片段上方)
在 Widget click 上调用以下方法:
放大
mMap.animateCamera(CameraUpdateFactory.zoomIn())
缩小
mMap.animateCamera(CameraUpdateFactory.zoomOut())
编辑:如果您希望将标记放置在左下角,则需要计算新的 LatLang 值,该值将略微位于所需位置的右侧和顶部,并相应地移动相机。例如,如果您的缩放级别为 16,则使用如下内容:
var lat = markerLatLng.latitude
var lng = markerLatLng.longitude
mMap.addMarker(MarkerOptions().position(LatLng(lat, lng)))
lat += 0.005
lng += 0.003
moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(lat, lng), 16f))
推荐阅读
- sql-server - 周四结束的 SQL 服务器周范围
- javascript - 如何根据chart.js中数据的开始时间和结束时间日期选择器之间的时间间隔格式化x轴?
- javascript - 无法使用 Node 12 ES6 Import 导入 OrbitControls
- c++ - 上下文菜单和图片框 C++
- c++ - 访问随机图像像素且最多一次的快速方法
- scala - Scala 的 Kafka 消费者中已弃用的 poll() 方法的替代方法是什么?
- c++ - C++ 编译错误未定义对 log4cplus 和 boost 的引用
- tensorflow - 如何使用我自己的 vgg19 文件而不是下载
- javascript - 暗模式+更改图片来源
- mysql - 查询Wordpress帖子时如何将类别和标签分成两个不同的列。?