codeman
codeman

Reputation: 9038

Allow pinching to zoom while animating to bearing with iOS Google Maps SDK

I'm using the animateToBearing method in the Google Maps SDK for iOS so that I can rotate the map with the device's compass: https://developers.google.com/maps/documentation/ios/views#bearing_orientation

While continuing to call this method, the map becomes unresponsive to the regular pinch to zoom functionality. Is there any way I can get the map to continue allowing pinch to zoom while also animating to the bearing?

I'm implementing it like this:

func locationManager(manager: CLLocationManager!, didUpdateHeading newHeading: CLHeading!) {
        mapView.animateToBearing(newHeading.magneticHeading)
}

Upvotes: 1

Views: 769

Answers (2)

Enrico Susatyo
Enrico Susatyo

Reputation: 19790

Before you ask the location manager to update the heading, make sure that you filter it so it doesn't update at every single minuscule movement. If you do, Google Map will be animating almost all the time, and it won't respond to your gesture while animating the map.

In Objective-C this is the code:

self.locationManager.headingFilter = 5;

You may experiment yourself, but I find changing it to around 1 to 5 degrees will make it very responsive while still enabling gestures.

Upvotes: 1

Kay_N
Kay_N

Reputation: 997

So I'm sorry misinterpreted the question before. I assumed you were using animateToZoom as well.

Answer: So not entirely sure if its possible because its somewhat by design. When moving the camera e.g. to a different point on the map, it logically makes sense to have a gesture stop that behaviour, and vice versa: e.g., if I'm holding the camera at a position with my held finger, triggering an explicit animation should still move it.

However, you might have a better time if you disable animations while changing the value, but I don't think it'll help too much because the 'set' will also stop a gesture. But an animation is more aggressively trying to stop it over its lifetime (e.g., over 250ms or whatever is the default).
Below is the implementation.

Hope that's clear and helpful.

CATransaction.begin()     
CATransaction.setDisableActions(true)
        map.animateToBearing(value)
        CATransaction.commit()

Upvotes: 0

Related Questions