Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable animation for changing GMSMarker position in iOS?

According to documentation you can change marker position with animation:

Marker position. Animated.

Do you know how to disable this animation?

like image 212
Roman Barzyczak Avatar asked Oct 25 '16 14:10

Roman Barzyczak


2 Answers

Suppose your reference for marker is mainMarker which is a GMSMarker object

var mainMarker:GMSMarker?

And suppose this is your function to change marker position without animation

func changeMarkerWithoutAnimation() {
    mainMarker?.map = nil
    mainMarker = nil
    let changedPosition = CLLocationCoordinate2DMake(22.9734, 78.6569)
    mainMarker = GMSMarker(position: changedPosition)
    mainMarker?.title = "Hello World"
    mainMarker!.map = mapView
}

This will change your marker's position without animation.

like image 113
Rajan Maheshwari Avatar answered Sep 28 '22 02:09

Rajan Maheshwari


As implemented in google maps samples, you should use CATransaction for this purpose.

let changedPosition = CLLocationCoordinate2DMake(22.9734, 78.6569)
CATransaction.begin()
CATransaction.setAnimationDuration(0.0)
marker.position = changedPosition
CATransaction.commit()

Source demo.

like image 25
Maksym Savisko Avatar answered Sep 28 '22 04:09

Maksym Savisko