点击Google地图标记时尝试运行功能

时间:2016-06-23 04:21:08

标签: ios swift google-maps parse-platform

我正在尝试运行一个功能,当点击谷歌地图上的标记时会播放视频但是我无法运行该功能,尽管没有错误。也许我的逻辑或控制流程存在问题。下面是我的视图控制器以及功能。

@IBOutlet weak var viewMap: GMSMapView!

var placesClient: GMSPlacesClient?

var url : NSURL?
var videoData : NSData?
var doUpload : Bool?
var FriendsOrPublic : String?
var dataPath : String?
var gmsPlace : GMSPlace?
var gpsCoordinates : CLLocationCoordinate2D?
let locationManager = CLLocationManager()


override func viewDidLoad() {
    super.viewDidLoad()
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.startUpdatingLocation()
    }
    //placesClient = GMSPlacesClient()
    var gmsPlace : GMSPlace?
    let placesClient = GMSPlacesClient.sharedClient()
    placesClient.currentPlaceWithCallback { (placeLikelihoods, error) -> Void in
        guard error == nil else {
            print("Current Place error: \(error!.localizedDescription)")
            return
        }

        if let placeLikelihoods = placeLikelihoods {
            for likelihood in placeLikelihoods.likelihoods {
                gmsPlace = likelihood.place
                //print("Current Place name \(gmsPlace.name) at likelihood \(likelihood.likelihood)")
                //print("Current Place address \(gmsPlace.formattedAddress)")
                //print("Current Place attributions \(gmsPlace.attributions)")
                //print("Current PlaceID \(gmsPlace.placeID)")
                self.gpsCoordinates = (gmsPlace!.coordinate)

            }
            //print(self.gpsCoordinates)

        }
    }
    let testObject = PFObject(className: "TestObject")
    testObject["foo"] = "bar"
    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        print("Object has been saved.")
    }

    print(url)
    print(videoData)
    print(doUpload)
    print(FriendsOrPublic)
    print(dataPath)
    if doUpload == true {
        Upload()
    }

    Download()
    viewMap.delegate = self

}

 func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    //print("locations = \(locValue.latitude) \(locValue.longitude)")
    gpsCoordinates = locValue
    let camera = GMSCameraPosition.cameraWithTarget(gpsCoordinates!, zoom: 16.9)
    //let camera = GMSCamera
    print(camera)
    viewMap.camera = camera
    viewMap.myLocationEnabled = true
    viewMap.settings.myLocationButton = false


    let marker = GMSMarker()
    marker.position = self.gpsCoordinates!
    marker.title = "Newport Beach"
    marker.snippet = "California"
    marker.map = viewMap
    locationManager.stopUpdatingLocation()
}
var marker : GMSMarker!
func Download() {
    let query = PFQuery(className:"UploadedVideoCurrent")

    //        query.whereKey("GPS", equalTo: "ChIJTbSOh8Pf3IARt311y2Wqspc")
    query.whereKey("typeofPost", equalTo: "Public")
    query.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error: NSError?) -> Void in

        if error == nil {
            // The find succeeded.
            print("Successfully retrieved \(objects!.count) coordinates.")
            // Do something with the found objects
            if let objects = objects {
                for object in objects {
                    print(object.objectForKey("GPS"))
                    let postsLat = object.objectForKey("GPS")!.latitude as Double
                    let postsLong = object.objectForKey("GPS")!.longitude as Double
                    let position: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: postsLat, longitude:postsLong)

                    self.marker = GMSMarker(position: position)
                    self.marker.map = self.viewMap
                }
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
        }
    }
}
func viewMap(viewMap: GMSMapView, didTapMarker marker: GMSMarker)
{
    print("tapped")
}

1 个答案:

答案 0 :(得分:0)

您正在调用错误的委托功能。你仍然应该调用函数" mapView"因为那是如何定义委托函数的,即使你的地图本身被声明为" viewMap"

func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {
       print("tapped")
}