@@ -27,7 +27,8 @@ class NewKlusterViewController: UIViewController, UIImagePickerControllerDelegat
2727
2828 @IBOutlet var hideKeyboardInputAccessoryView : UIView !
2929 private var featuredImage : UIImage !
30-
30+ private var klusterLocation : PFGeoPoint !
31+
3132 @IBOutlet weak var chooseLocationPressed : DesignableButton !
3233
3334 override func preferredStatusBarStyle( ) -> UIStatusBarStyle {
@@ -86,10 +87,43 @@ class NewKlusterViewController: UIViewController, UIImagePickerControllerDelegat
8687 }
8788
8889 @IBAction func chooseLocationButtonClicked( sender: DesignableButton ) {
89- let storyboard = UIStoryboard . init ( name: " Map " , bundle: nil )
90- let mapController = storyboard. instantiateInitialViewController ( )
91- self . presentViewController ( mapController!, animated: true , completion: nil )
90+ let actionSheet = UIAlertController . init ( title: " Select Kluster Location " , message: nil , preferredStyle: . ActionSheet)
91+
92+ let currentLocationAction = UIAlertAction . init ( title: " Current Location " , style: . Default) { ( action) -> Void in
93+ PFGeoPoint . geoPointForCurrentLocationInBackground ( { ( geoPoint, error) -> Void in
94+ if ( error != nil ) {
95+ print ( " Error grabbing current location " )
96+ let alert = UIAlertController . init ( title: " Error " , message: " Unable to get your current location. Please try again. " , preferredStyle: . Alert)
97+ let ok = UIAlertAction . init ( title: " Okay " , style: . Default, handler: nil )
98+ alert. addAction ( ok)
99+ self . presentViewController ( alert, animated: true , completion: nil )
100+ } else {
101+ self . klusterLocation = geoPoint
102+ }
103+ } )
104+ }
105+
106+ actionSheet. addAction ( currentLocationAction)
107+
108+ let pickLocation = UIAlertAction . init ( title: " Pick A Location " , style: . Default) { ( action) -> Void in
109+ self . presentViewController ( actionSheet, animated: true , completion: nil )
110+ let storyboard = UIStoryboard . init ( name: " Map " , bundle: nil )
111+ let mapController = storyboard. instantiateInitialViewController ( ) as! UINavigationController
112+ // let locationController = mapController.childViewControllers.first as! LocationSelectViewController
113+ self . presentViewController ( mapController, animated: true , completion: nil )
114+ }
115+
116+ actionSheet. addAction ( pickLocation)
117+
118+ let cancelAction = UIAlertAction . init ( title: " Cancel " , style: . Cancel) { ( action) -> Void in
119+ actionSheet. dismissViewControllerAnimated ( true , completion: nil )
120+ }
121+
122+ actionSheet. addAction ( cancelAction)
123+
124+ self . presentViewController ( actionSheet, animated: true , completion: nil )
92125 }
126+
93127 @IBAction func selectFeaturedImageButtonClicked( sender: DesignableButton ) {
94128
95129 let authorization = PHPhotoLibrary . authorizationStatus ( )
@@ -168,9 +202,11 @@ class NewKlusterViewController: UIViewController, UIImagePickerControllerDelegat
168202 let params = [ " title " : title!,
169203 " summary " : summary!,
170204 " plans " : plans!,
171- " photo " : base64String!] as Dictionary < String , String >
205+ " latitude " : self . klusterLocation. latitude,
206+ " longitude " : self . klusterLocation. longitude,
207+ " photo " : base64String!]
172208
173- KlusterDataSource . createKlusterWithParams ( params, completion: { ( object, error) -> Void in
209+ KlusterDataSource . createKlusterWithParams ( params as [ NSObject : AnyObject ] , completion: { ( object, error) -> Void in
174210 if error != nil {
175211 hud. removeFromSuperview ( )
176212 } else {
0 commit comments