Swift谷歌地图 - 当标记点击时如何在屏幕底部移动标记?

时间:2015-11-27 08:50:32

标签: ios swift google-maps

我正在玩谷歌地图,我需要覆盖点击标记的默认行为 - 默认情况下,标记会转到屏幕的中心,并且上面会显示信息窗口。我需要找出一种方法,当标记被点击时,标记移动到屏幕的底部,infowindow显示在中心。我找到了解决方案here,但我无法将其转换为快速

请帮忙吗?

2 个答案:

答案 0 :(得分:4)

func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {

    mapView.animateToLocation(marker.position)
    mapView.selectedMarker = marker

    var point = mapView.projection.pointForCoordinate(marker.position)
    point.y = point.y - 200

    var newPoint = mapView.projection.coordinateForPoint(point)
    var camera = GMSCameraUpdate.setTarget(newPoint)
    mapView.animateWithCameraUpdate(camera)

    return true

}

答案 1 :(得分:1)

添加GMSMapViewDelegate

 // move marker


   func updateLocationoordinates(coordinates:CLLocationCoordinate2D) {
        if marker == nil
        {
            marker = GMSMarker()
            marker.position = coordinates
            let image = UIImage(named:"destinationmarker")
            marker.icon = image
            marker.map = mapPageView
            marker.appearAnimation = GMSMarkerAnimation.pop
        }
        else
        {
            CATransaction.begin()
//            CATransaction.setAnimationDuration(0.1)
            marker.position =  coordinates
            CATransaction.commit()
        }
        print(coordinates)
    }

相机更改此方法每次都会调用

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {

    var destinationLocation = CLLocation()
    destinationLocation = CLLocation(latitude: position.target.latitude,  longitude: position.target.longitude)
    destinationCoordinate = destinationLocation.coordinate
    updateLocationoordinates(coordinates: destinationCoordinate)

}
祝你好运