问题
Im having an error while trying to animate a GMSMarker, I have followed the Google documentation and various guides but it keeps returning an error, below is my code:
func placeMarker(coordinate: CLLocationCoordinate2D) {
if locationMarker != nil {
locationMarker.map = nil
}
locationMarker = GMSMarker(position: coordinate)
locationMarker.icon = GMSMarker.markerImageWithColor(purple)
locationMarker.appearAnimation = kGMSMarkerAnimationPop
locationMarker.snippet = "The best place on earth."
locationMarker.map = mapView
}
Which returns the error Ambiguous use of 'kGMSMarkerAnimationPop'
Any help would be appriciated!
回答1:
upgrading google map pod won't work, at least until 1.12.3.
change GMSMarkerAnimation in GMSMarker.h from this:
typedef enum { /** No animation (default). */ kGMSMarkerAnimationNone = 0, /** The marker will pop from its groundAnchor when added. */ kGMSMarkerAnimationPop, } GMSMarkerAnimation;to this:
typedef NS_ENUM(NSInteger, GMSMarkerAnimation){ /** No animation (default). */ kGMSMarkerAnimationNone = 0, /** The marker will pop from its groundAnchor when added. */ kGMSMarkerAnimationPop, } ;change
locationMarker.appearAnimation = kGMSMarkerAnimationPopto
locationMarker.appearAnimation = GMSMarkerAnimation.Pop
回答2:
In Swift 3/GoogleMaps 2.3.0. The new syntax is :
marker.appearAnimation = GMSMarkerAnimation.pop
回答3:
For me this happens when I upgrade from GoogleMap 1.10.3 to 1.11.1 using CocoaPod. Previously using 1.10.3 it requires me to import all of the header files of GoogleMap in Bridging-Header.h file.
To remove this ambiguous error, I just commented out all the imported headers in Bridging-Header.h
回答4:
I looked around and I found an answer that worked for me:
locationMarker.appearAnimation = GoogleMaps.kGMSMarkerAnimationPop
回答5:
Swift 3
marker.appearAnimation = kGMSMarkerAnimationpop
Swift 4
marker.appearAnimation = GMSMarkerAnimation.pop
来源:https://stackoverflow.com/questions/34656475/ambiguous-use-of-kgmsmarkeranimationpop-error-in-swift-2