Created
March 2, 2015 04:17
-
-
Save macbaszii/de6daf32f06b33406174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PlacePickerViewController.swift | |
// TaxiReporter | |
// | |
// Created by Kiattisak Anoochitarom on 2/27/2558 BE. | |
// Copyright (c) 2558 Kiattisak Anoochitarom. All rights reserved. | |
// | |
import UIKit | |
import FacebookSDK | |
import CoreLocation | |
protocol PlacePickerDelegate { | |
func placePicker(picker: PlacePickerViewController, didSelectPlace place: FacebookPlace) | |
} | |
class PlacePickerViewController: FBPlacePickerViewController { | |
var placeSelectionDelegate: PlacePickerDelegate? | |
var locationManager: CLLocationManager! | |
override func viewDidLoad() { | |
setupFacebookPlacePicker() | |
setupLocationManager() | |
} | |
} | |
extension PlacePickerViewController { | |
// MARK: - Action | |
@IBAction func cancel(sender: AnyObject) { | |
dismissViewControllerAnimated(true, completion: nil) | |
} | |
// MARK: - Internal method | |
private func setupFacebookPlacePicker() { | |
delegate = self | |
doneButton = nil | |
cancelButton = nil | |
} | |
private func setupLocationManager() { | |
locationManager = CLLocationManager() | |
locationManager.desiredAccuracy = kCLLocationAccuracyBest | |
locationManager.delegate = self | |
if CLLocationManager.authorizationStatus() == .NotDetermined { | |
locationManager.requestWhenInUseAuthorization() | |
} | |
} | |
} | |
extension PlacePickerViewController: CLLocationManagerDelegate { | |
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { | |
locationManager.stopUpdatingLocation() | |
locationManager = nil | |
var currentLocation = locations.last! as CLLocation | |
locationCoordinate = currentLocation.coordinate | |
loadData() | |
} | |
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) { | |
if status == .AuthorizedWhenInUse { | |
manager.startUpdatingLocation() | |
} | |
} | |
} | |
extension PlacePickerViewController: FBPlacePickerDelegate { | |
func placePickerViewControllerSelectionDidChange(placePicker: FBPlacePickerViewController!) { | |
var selectedPlace = FacebookPlace(place: placePicker.selection) | |
placeSelectionDelegate?.placePicker(self, didSelectPlace: selectedPlace) | |
} | |
func placePickerViewController(placePicker: FBPlacePickerViewController!, handleError error: NSError!) { | |
showBasicAlertControllerWith(title: "Facebook Error", message: error.localizedDescription, completion: nil) | |
} | |
func placePickerViewControllerDataDidChange(placePicker: FBPlacePickerViewController!) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment