google-maps - 如何放大设备的实际位置?

标签 google-maps android-studio kotlin

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

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)


}

最佳答案

通常,您可以通过更改 map 的相机位置来更改 map 的缩放级别。根据此documentation:

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.



由于您没有提供完整的代码,因此让我在下面插入示例:
  • 如果要使所有其他 map 属性保持不变,而只是更改缩放级别,则可以使用以下行:
    //where zoomLevel is your preferred zoom level
    mMap.moveCamera(CameraUpdateFactory.zoomTo(zoomLevel)) 
    
  • 如果要在放置标记的位置缩放 map ,则在addMarker()函数下方,可以添加以下行以在City级别缩放 map :
    // 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()
  • ,则可以动画相机 View 更新

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

    关于google-maps - 如何放大设备的实际位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58066884/

    相关文章:

    javascript - Google map Javascript API V3 - 连续平移

    javascript - 加载 Google map API 时出现问题

    android - 在android中从一个 fragment 切换到另一个 fragment 时如何存储 fragment 数据?

    java - 嵌套的 ListViews 没有扩展到全高

    javascript - 谷歌地图 API V3 : Exclude single marker from clustering

    google-maps - 如何将邮政编码搜索框添加到我的 Google map ,它只会搜索我的标记

    java - 我怎样才能做出确认对话框?

    kotlin - 对于最后一个类,为什么会提示呢?

    java - @JsonView 注释不起作用

    android - 在动态特性模块之间共享信息