Last active
May 8, 2018 03:53
-
-
Save PattyAppier/ca27031ff8347041b42088410a61add9 to your computer and use it in GitHub Desktop.
PattysCharmDriverApp
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
``` | |
// PassengersViewController.swift | |
// PattysCharmDriverApp | |
// Created by Patty Chen on 2018/5/07. | |
// Copyright © 2018年 Patty Chen. All rights reserved. | |
import UIKit | |
import MapKit | |
class PassengersViewController: UIViewController, CLLocationManagerDelegate { | |
// May 7, to use @ attributes to connect UI and Code for Outlet. | |
@IBOutlet weak var logOutOLBTN: UIBarButtonItem! | |
@IBOutlet weak var callDriverOLBTN: UIButton! | |
@IBOutlet weak var passengersMapOLVW: MKMapView! | |
// May 7, to use CLManager Class to show location of Passenger. | |
var showPassengersLocation = CLLocationManager() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
showPassengersLocation.delegate = self | |
showPassengersLocation.desiredAccuracy = kCLLocationAccuracyBest | |
showPassengersLocation.requestWhenInUseAuthorization() // to add location when in Use in App's info | |
showPassengersLocation.startUpdatingLocation() | |
} | |
// May 7, to use the Method called "didUpdateLocations" to update Passengers Location by passing value to Delegate . | |
// to call out method by typing Func with keyword "didUpdateLocations" and to use _ manager as breifing key constant name for class of CLLocationManager. | |
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | |
if let coordPassenger = manager.location?.coordinate { | |
let centerPassenger = CLLocationCoordinate2D(latitude: coordPassenger.latitude, longitude: coordPassenger.longitude) | |
let regionPassenger = MKCoordinateRegion(center: centerPassenger, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)) | |
// May 7. to do initializer | |
passengersMapOLVW.setRegion(regionPassenger, animated: true) | |
// to range the Geo view where Passenger located. | |
passengersMapOLVW.removeAnnotations(passengersMapOLVW.annotations) | |
//remove previous annotation of Passager. | |
let annotation = MKPointAnnotation() // to declare remark of where Passenger is. | |
annotation.coordinate = centerPassenger | |
annotation.title = " Dear Customer, this is your Location now !" | |
passengersMapOLVW.addAnnotation(annotation) | |
} | |
} | |
// May 7, to use @ attributes to connect UI and Code for Action. | |
@IBAction func logOutActionBTN(_ sender: UIBarButtonItem) { | |
} | |
@IBAction func callDriverActionBTN(_ sender: UIButton) { | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment