L12 mapView
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
super.viewDidLoad()
mapView.delegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = CLLocationCoordinate2DMake(locations[0].coordinate.latitude, locations[0].coordinate.longitude)
let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
let region = MKCoordinateRegion(center: location, span: span)
self.mapView.setRegion(region, animated: true)
}
導航模式 ViewController
let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
let region = MKCoordinateRegion(center: location, span: span)
self.mapView.setRegion(region, animated: true)
}
導航模式 ViewController
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if transmittedLatitude != 0{
if transmittedLongitude != 0{
self.requestCLLocation = CLLocation(latitude: transmittedLatitude, longitude: transmittedLongitude)
}
}
CLGeocoder().reverseGeocodeLocation(requestCLLocation) { (placemarks, error) in
if let placemark = placemarks{
if placemark .count > 0 {
let newPlaceMark = MKPlacemark(placemark: placemark[0])
let item = MKMapItem(placemark: newPlaceMark)
item.name = self.transmittedTitle
//選擇啟用導航時的選項
let lanuchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeWalking]
item.openInMaps(launchOptions: lanuchOptions)
}
}
}
}
L110 客製化鍵盤
L113 JSON Fetch
新課程,但error handling還沒有做好,有反應,待最佳解
L110 客製化鍵盤
L113 JSON Fetch
新課程,但error handling還沒有做好,有反應,待最佳解
留言
張貼留言