Ambiguous use of 'kGMSMarkerAnimationPop' Error in Swift 2

偶尔善良 提交于 2019-12-12 12:27:57

问题


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.

  1. 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,
    } ;
    
  2. change

    locationMarker.appearAnimation = kGMSMarkerAnimationPop

    to

    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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!