首页 > 解决方案 > 如何放大设备的实际位置?

问题描述

我无法放大设备的当前位置,有人可以帮我吗?欢迎任何帮助。

override fun onMapReady(googleMap: GoogleMap) {
    Log.i("MAP READY", "READY")
    val position = if (currentLocation != null) LatLng(currentLocation!!.latitude, currentLocation!!.longitude) else null
    this.map = googleMap
    
    getFineLocationPermission()
    this.map!!.setOnMarkerClickListener(this)
    this.map!!.uiSettings.isRotateGesturesEnabled = true
    this.map!!.uiSettings.isZoomGesturesEnabled = true
    this.map!!.setOnInfoWindowClickListener(this)
    this.map!!.setOnMapLongClickListener(this)


}

在此处输入图像描述

标签: google-mapsandroid-studiokotlin

解决方案


通常,您可以通过更改相机位置来更改地图的缩放级别。根据此文档

To change the position of the camera, you must specify where you want to move the camera, using a CameraUpdate. The Maps API allows you to create many different types of CameraUpdate using CameraUpdateFactory.

由于您没有提供完整的代码,让我在下面插入示例:

  • 如果您想保持所有其他地图属性相同并仅更改缩放级别,则可以使用以下行:

    //where zoomLevel is your preferred zoom level
    mMap.moveCamera(CameraUpdateFactory.zoomTo(zoomLevel)) 
    
  • 如果您想在放置标记的位置缩放地图,那么在您的功能下方,您可以添加这条线以在一个级别addMarker()上缩放您的地图:City

    // zoomLevel is set at 10 for a City-level view
    val zoomLevel = 10
    // latLng contains the coordinates where the marker is added
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,zoomLevel)) 
    

    有趣的提示:如果您使用而不是使用,您可以 为相机视图更新设置动画 animateCamera() moveCamera()

有关 Android 版 Maps SDK -相机和视图设置的更多信息,请参阅https://developers.google.com/maps/documentation/android-sdk/views


推荐阅读