diff --git a/iOSDevUK/Controllers/Maps/AllLocationsMapViewController.swift b/iOSDevUK/Controllers/Maps/AllLocationsMapViewController.swift
index 8516c97..8058032 100644
--- a/iOSDevUK/Controllers/Maps/AllLocationsMapViewController.swift
+++ b/iOSDevUK/Controllers/Maps/AllLocationsMapViewController.swift
@@ -36,6 +36,10 @@ class AllLocationsMapViewController: UIViewController, UITableViewDelegate, UITa
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
+
+ // In case this is the first time showing a map screen
+ // request permission to use the user's location
+ CLLocationManager().requestWhenInUseAuthorization()
}
// MARK: - Navigation
@@ -77,11 +81,12 @@ class AllLocationsMapViewController: UIViewController, UITableViewDelegate, UITa
func showMapLocations(forIndexPath indexPath: IndexPath) {
mapView.removeAnnotations(mapView.annotations)
- guard let locations = locationTypes?[indexPath.row].locations else {
+ guard let locationTypes = locationTypes else {
print("Unable to access list of locations")
return
}
+ let locations = locationTypes[indexPath.row].locations
showMapAnnotations(locations: locations)
let region = regionForLocations(locations: locations)
@@ -90,6 +95,10 @@ class AllLocationsMapViewController: UIViewController, UITableViewDelegate, UITa
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
+ // Avoid overriding the user's location annotation view, use the default
+ guard !(annotation is MKUserLocation) else {
+ return nil
+ }
let identifier = "iosdevukLocation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
diff --git a/iOSDevUK/Controllers/Maps/MapLocationViewController.swift b/iOSDevUK/Controllers/Maps/MapLocationViewController.swift
index ef9b592..980a292 100644
--- a/iOSDevUK/Controllers/Maps/MapLocationViewController.swift
+++ b/iOSDevUK/Controllers/Maps/MapLocationViewController.swift
@@ -50,7 +50,19 @@ class MapLocationViewController: UIViewController, MKMapViewDelegate, SFSafariVi
// Dispose of any resources that can be recreated.
}
+ override func viewWillAppear(_ animated: Bool) {
+ super.viewWillAppear(animated)
+
+ // In case this is the first time showing a map screen
+ // request permission to use the user's location
+ CLLocationManager().requestWhenInUseAuthorization()
+ }
+
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
+ // Avoid overriding the user's location annotation view, use the default
+ guard !(annotation is MKUserLocation) else {
+ return nil
+ }
let identifier = "iosdevukLocation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
diff --git a/iOSDevUK/Info.plist b/iOSDevUK/Info.plist
index 2e71813..720a5f3 100644
--- a/iOSDevUK/Info.plist
+++ b/iOSDevUK/Info.plist
@@ -25,6 +25,8 @@
NSAllowsArbitraryLoads
+ NSLocationWhenInUseUsageDescription
+ The app will show your location on maps it presents
UILaunchStoryboardName
LaunchScreen
UIMainStoryboardFile
diff --git a/iOSDevUK/Storyboards/MainStoryboard.storyboard b/iOSDevUK/Storyboards/MainStoryboard.storyboard
index 878118d..15a163e 100644
--- a/iOSDevUK/Storyboards/MainStoryboard.storyboard
+++ b/iOSDevUK/Storyboards/MainStoryboard.storyboard
@@ -2,6 +2,7 @@
+
@@ -17,7 +18,7 @@
-
+
@@ -222,10 +223,10 @@ Information
-
+
-