Setting CLLocation2D for use in MKLaunchOptions

157 views Asked by At

I am totally lost! I am trying to set up the detail disclosure action. But, am confused on how to get the coordinates out of viewDidAppear. Please any advice would be much appreciated! Here is my code:

@IBOutlet weak var mapView: MKMapView!
var MapViewLocationManager:CLLocationManager! = CLLocationManager()
var currentLocation: PFGeoPoint! = PFGeoPoint()
let locationManager = CLLocationManager()
let annotation = MKPointAnnotation()
var locationLat: CLLocationCoordinate2D!
var locationLong: CLLocationCoordinate2D!

override func viewDidAppear(animated: Bool) {
    var annotationQuery = PFQuery(className: "oysterBarsSF")
    currentLocation = PFGeoPoint(location: MapViewLocationManager.location)
    annotationQuery.whereKey("Location", nearGeoPoint: currentLocation, withinMiles: 5000)
    annotationQuery.findObjectsInBackgroundWithBlock{
        (bars, error) -> Void in
        if error == nil {
            println("Successful query")
            let myBars = bars as! [PFObject]

            for bar in myBars {
                let point = bar["Location"] as! PFGeoPoint
                self.annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
                self.annotation.title = bar["Name"] as! String!
                self.annotation.subtitle = bar["Hours"] as! String!
                self.mapView.addAnnotation(self.annotation)

                locationLat(): point.latitude
                locationLong(): point.longitude

            }
        } else {
            println("Error")
        }
    }

}

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!,
    calloutAccessoryControlTapped control: UIControl!) {
        let addressDictionary = [String(kABPersonAddressStreetKey)]
        let location = self.annotation
        let coordinate = CLLocationCoordinate2D(latitude: locationLat, longitude: locationLong)
        let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
        let mapItem = MKMapItem(placemark: placemark)
        mapItem.name = title
        let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
        mapItem.openInMapsWithLaunchOptions(launchOptions)
}
0

There are 0 answers