jeudi 23 juin 2016

Attempting to run a function when Google Maps Marker is tapped

I am attempting to run a function that will play a video when a marker on google maps is tapped however I cannot get that function to run although there are no errors. Perhaps there is an issue with my logic or control flow. Below is my view controller as well as the function. @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") }

Aucun commentaire:

Enregistrer un commentaire