【问题标题】:IOS : Rough behaviour at the boundaries of google mapsIOS:谷歌地图边界的粗暴行为
【发布时间】:2018-03-01 14:26:03
【问题描述】:

我正在为 IOS 使用谷歌地图 SDK。我已经使用 GMSCoordinateBounds() 方法设置了地图的边界。

我在地图边界处滚动时遇到了一些问题。 不确定,这是 IOS 原生行为还是与代码相关的东西。

实际行为: 在边界处经历粗暴行为。 在界限内工作正常。

预期行为: 它应该在边界处停止滚动或放大效果,以避免粗暴行为。

这是我的代码

var mapView = GMSMapView()
var defaultCamera = GMSCameraPosition()
defaultCamera = GMSCameraPosition(target: CLLocationCoordinate2D(latitude: 12.3019, longitude: 104.0923),
                                      zoom: zoomLevels[0],
                                      bearing: defaultCamera.bearing,
                                      viewingAngle: defaultCamera.viewingAngle)
mapView.delegate = self
mapView.mapStyle = MapUtils().style
mapView.camera = defaultCamera
mapView.setMinZoom(10, maxZoom: 21)
// enable google map view handle other gesture
mapView.settings.consumesGesturesInView = false
mapView.settings.rotateGestures = false
mapView.settings.tiltGestures = false
mapView.settings.allowScrollGesturesDuringRotateOrZoom = false
// override double tap to zoom in
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(googleMapDoubleTap))
tapGesture.numberOfTapsRequired = 2
mapView.addGestureRecognizer(tapGesture)

self.myLocationMarker.map = self.mapView

任何帮助将不胜感激。 提前谢谢..

【问题讨论】:

    标签: ios google-maps google-maps-sdk-ios


    【解决方案1】:

    解决办法就是在配置GMSMapview的时候简单的加上这一行:

    _mapView.settings.allowScrollGesturesDuringRotateOrZoom = NO;
    

    您可以使用此行 allowScrollGesturesDuringRotateOrZoom 到您的 GMSMapview。它控制旋转和缩放手势是否可以偏离中心和滚动。默认值为 YES。

    mapView.settings.allowScrollGesturesDuringRotateOrZoom = false // NO for obj-c and false for swift
    

    因此,通过将其设置为 NO/false,您现在可以在标记位置不移动时执行缩放。

    【讨论】:

    • 好的!非常感谢@MdRashedPervez。会看看它是否有效并让你知道
    • 嗨@MdRashedPervez。很抱歉,但它不起作用
    • 同样的错误显示?你设置了 _mapView.settings.allowScrollGesturesDuringRotateOrZoom = NO;在你的 GMSMapview 中?
    • 我确实将它设置为 false
    • 如果你在这里分享你的代码,它会更容易理解。添加 mapkitView 时是否将约束设置为 0?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多