Commit 1377bbc9 authored by Ariba Siddiqui's avatar Ariba Siddiqui
Browse files

Revert "comments for directions and other restructuring"

This reverts commit 05261150
parent 05261150
No preview for this file type
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
09AD0D752753EF1C00E400F7 /* MapSerachView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AD0D742753EF1C00E400F7 /* MapSerachView.swift */; };
09AD0D772753EF5000E400F7 /* LocationSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AD0D762753EF5000E400F7 /* LocationSearch.swift */; }; 09AD0D772753EF5000E400F7 /* LocationSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AD0D762753EF5000E400F7 /* LocationSearch.swift */; };
2517A35527502266006F2B81 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35427502266006F2B81 /* AppDelegate.swift */; }; 2517A35527502266006F2B81 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35427502266006F2B81 /* AppDelegate.swift */; };
2517A35727502266006F2B81 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35627502266006F2B81 /* SceneDelegate.swift */; }; 2517A35727502266006F2B81 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35627502266006F2B81 /* SceneDelegate.swift */; };
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
09AD0D742753EF1C00E400F7 /* MapSerachView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapSerachView.swift; sourceTree = "<group>"; };
09AD0D762753EF5000E400F7 /* LocationSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearch.swift; sourceTree = "<group>"; }; 09AD0D762753EF5000E400F7 /* LocationSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearch.swift; sourceTree = "<group>"; };
2517A35127502266006F2B81 /* Location Tutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Location Tutorial.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 2517A35127502266006F2B81 /* Location Tutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Location Tutorial.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2517A35427502266006F2B81 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 2517A35427502266006F2B81 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
...@@ -108,6 +110,7 @@ ...@@ -108,6 +110,7 @@
2517A35D2750226C006F2B81 /* Assets.xcassets */, 2517A35D2750226C006F2B81 /* Assets.xcassets */,
2517A35F2750226C006F2B81 /* LaunchScreen.storyboard */, 2517A35F2750226C006F2B81 /* LaunchScreen.storyboard */,
2517A3622750226C006F2B81 /* Info.plist */, 2517A3622750226C006F2B81 /* Info.plist */,
09AD0D742753EF1C00E400F7 /* MapSerachView.swift */,
09AD0D762753EF5000E400F7 /* LocationSearch.swift */, 09AD0D762753EF5000E400F7 /* LocationSearch.swift */,
); );
path = "Location Tutorial"; path = "Location Tutorial";
...@@ -263,6 +266,7 @@ ...@@ -263,6 +266,7 @@
files = ( files = (
09AD0D772753EF5000E400F7 /* LocationSearch.swift in Sources */, 09AD0D772753EF5000E400F7 /* LocationSearch.swift in Sources */,
2517A35927502266006F2B81 /* ViewController.swift in Sources */, 2517A35927502266006F2B81 /* ViewController.swift in Sources */,
09AD0D752753EF1C00E400F7 /* MapSerachView.swift in Sources */,
2517A35527502266006F2B81 /* AppDelegate.swift in Sources */, 2517A35527502266006F2B81 /* AppDelegate.swift in Sources */,
2517A35727502266006F2B81 /* SceneDelegate.swift in Sources */, 2517A35727502266006F2B81 /* SceneDelegate.swift in Sources */,
); );
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "84" startingLineNumber = "86"
endingLineNumber = "84" endingLineNumber = "86"
landmarkName = "goButtonTapped(_:)" landmarkName = "goButtonTapped(_:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "103" startingLineNumber = "105"
endingLineNumber = "103" endingLineNumber = "105"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "104" startingLineNumber = "106"
endingLineNumber = "104" endingLineNumber = "106"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -62,10 +62,58 @@ ...@@ -62,10 +62,58 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "105" startingLineNumber = "107"
endingLineNumber = "105" endingLineNumber = "107"
landmarkName = "getDirections()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "298D89E0-B8E7-4739-97A7-7799C4E2704E"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "109"
endingLineNumber = "109"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
<Locations>
<Location
uuid = "298D89E0-B8E7-4739-97A7-7799C4E2704E - 5a8fd180874c388"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Location_Tutorial.ViewController.getDirections() -&gt; ()"
moduleName = "Location Tutorial"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aribasiddiqui/Downloads/Location%20Tutorial/Location%20Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "100"
endingLineNumber = "100"
offsetFromSymbolStart = "428">
</Location>
<Location
uuid = "298D89E0-B8E7-4739-97A7-7799C4E2704E - 53aed4c77a2b419f"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 (Swift.Optional&lt;__C.MKDirectionsResponse&gt;, Swift.Optional&lt;Swift.Error&gt;) -&gt; () in Location_Tutorial.ViewController.getDirections() -&gt; ()"
moduleName = "Location Tutorial"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aribasiddiqui/Downloads/Location%20Tutorial/Location%20Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "100"
endingLineNumber = "100"
offsetFromSymbolStart = "108">
</Location>
</Locations>
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
...@@ -78,8 +126,8 @@ ...@@ -78,8 +126,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "113" startingLineNumber = "111"
endingLineNumber = "113" endingLineNumber = "111"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -94,8 +142,8 @@ ...@@ -94,8 +142,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "119" startingLineNumber = "113"
endingLineNumber = "119" endingLineNumber = "113"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -110,8 +158,8 @@ ...@@ -110,8 +158,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "120" startingLineNumber = "114"
endingLineNumber = "120" endingLineNumber = "114"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -126,12 +174,28 @@ ...@@ -126,12 +174,28 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "126" startingLineNumber = "119"
endingLineNumber = "126" endingLineNumber = "119"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "09F7531A-1930-428C-96D6-F706EE65214C"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "125"
endingLineNumber = "125"
landmarkName = "createDirectionsRequest(from:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
...@@ -142,8 +206,24 @@ ...@@ -142,8 +206,24 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "134" startingLineNumber = "126"
endingLineNumber = "134" endingLineNumber = "126"
landmarkName = "createDirectionsRequest(from:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C3FEF63B-F36D-41E8-80DF-D4F88C907C81"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "128"
endingLineNumber = "128"
landmarkName = "createDirectionsRequest(from:)" landmarkName = "createDirectionsRequest(from:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -158,8 +238,8 @@ ...@@ -158,8 +238,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "135" startingLineNumber = "127"
endingLineNumber = "135" endingLineNumber = "127"
landmarkName = "createDirectionsRequest(from:)" landmarkName = "createDirectionsRequest(from:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -174,12 +254,28 @@ ...@@ -174,12 +254,28 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "136" startingLineNumber = "129"
endingLineNumber = "136" endingLineNumber = "129"
landmarkName = "createDirectionsRequest(from:)" landmarkName = "createDirectionsRequest(from:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "62E4DD88-9016-4FF0-9C32-5FBF2E22A604"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "140"
endingLineNumber = "140"
landmarkName = "resetMapView(withNew:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
...@@ -190,8 +286,8 @@ ...@@ -190,8 +286,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "108" startingLineNumber = "110"
endingLineNumber = "108" endingLineNumber = "110"
landmarkName = "getDirections()" landmarkName = "getDirections()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -206,8 +302,8 @@ ...@@ -206,8 +302,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "172" startingLineNumber = "165"
endingLineNumber = "172" endingLineNumber = "165"
landmarkName = "mapView(_:rendererFor:)" landmarkName = "mapView(_:rendererFor:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
...@@ -222,8 +318,8 @@ ...@@ -222,8 +318,8 @@
filePath = "Location Tutorial/ViewController.swift" filePath = "Location Tutorial/ViewController.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "171" startingLineNumber = "164"
endingLineNumber = "171" endingLineNumber = "164"
landmarkName = "mapView(_:rendererFor:)" landmarkName = "mapView(_:rendererFor:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" showsUserLocation="YES" showsCompass="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eRy-hV-Pvo"> <mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" showsUserLocation="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eRy-hV-Pvo">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
</mapView> </mapView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ac8-fP-bc3"> <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ac8-fP-bc3">
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// LocationFinder.swift // LocationFinder.swift
// MapKit Testing Search Functionality // MapKit Testing Search Functionality
// //
// Created by Brian Porumb on 25.11.21.
//
import Foundation import Foundation
import Combine import Combine
...@@ -9,7 +11,7 @@ import MapKit ...@@ -9,7 +11,7 @@ import MapKit
class LocationService: NSObject, ObservableObject { class LocationService: NSObject, ObservableObject {
// Different search states // Differnt search states
enum LocationStatus: Equatable { enum LocationStatus: Equatable {
case idle case idle
case noResults case noResults
......
// //
// MapSearchView.swift // ContentView.swift
// MapKit Testing Search Functionality // MapKit Testing Search Functionality
// //
// Created by Brian Porumb on 25.11.21.
//
import SwiftUI import SwiftUI
......
// //
// ViewController.swift // ViewController.swift
// MapKit Routing, Annotations and Location // Location Tutorial
//
// Created by Huang on 2021/11/25.
// //
import UIKit import UIKit
...@@ -12,31 +14,26 @@ class ViewController: UIViewController { ...@@ -12,31 +14,26 @@ class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView! @IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager() let locationManager = CLLocationManager()
var regionInMeters: Double = 10000 //scale of the map var regionInMeters: Double = 10000 //scale of the map
// ### code for directions start ###
var directionsArray: [MKDirections] = [] var directionsArray: [MKDirections] = []
// ### code for directions end ###
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
checkLocationServices() checkLocationServices()
setupMapView() setupMapView()
} }
func setupMapView(){
mapView.delegate=self
}
func setupLocationManager() { func setupLocationManager() {
locationManager.delegate = self locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.desiredAccuracy = kCLLocationAccuracyBest
} }
// helper function to display alerts to user
func displayAlert(alertTitle: String, alertMessage: String) {
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
func centerViewOnUserLocation() { func centerViewOnUserLocation() {
if let location = locationManager.location?.coordinate { if let location = locationManager.location?.coordinate {
let region = MKCoordinateRegion.init(center: location, latitudinalMeters: regionInMeters, longitudinalMeters: regionInMeters) let region = MKCoordinateRegion.init(center: location, latitudinalMeters: regionInMeters, longitudinalMeters: regionInMeters)
...@@ -44,18 +41,18 @@ class ViewController: UIViewController { ...@@ -44,18 +41,18 @@ class ViewController: UIViewController {
} }
} }
// check if user's location services are enabled
func checkLocationServices() { func checkLocationServices() {
if CLLocationManager.locationServicesEnabled() { if CLLocationManager.locationServicesEnabled() {
setupLocationManager() setupLocationManager()
checkLocationAuthorization() checkLocationAuthorization()
} else { } else {
print("Location Services are not enabled") // Show alert letting the user know they have to turn this on.
displayAlert(alertTitle: "Location Services are not turned on", alertMessage: "You must enable your Location Services to perform this action")
} }
} }
// checking authorization status
func checkLocationAuthorization() { func checkLocationAuthorization() {
let manager = CLLocationManager() let manager = CLLocationManager()
switch manager.authorizationStatus { switch manager.authorizationStatus {
...@@ -79,24 +76,29 @@ class ViewController: UIViewController { ...@@ -79,24 +76,29 @@ class ViewController: UIViewController {
} }
} }
// action triggered on the "GO" button tap // ### code for directions start ###
func setupMapView(){
mapView.delegate=self
}
@IBAction func goButtonTapped(_ sender: Any) { @IBAction func goButtonTapped(_ sender: Any) {
print("GO button tapped") print("GO button tapped")
getDirections() getDirections()
} }
//to prevent throttling and multiple renders func getLocationCoordinates() -> CLLocationCoordinate2D {
func resetMapView(withNew directions: MKDirections) { let cologne = MKPointAnnotation()
mapView.removeOverlays(mapView.overlays) cologne.title = "Cologne"
directionsArray.append(directions) cologne.coordinate = CLLocationCoordinate2D(latitude: 50.9375, longitude: 6.9603)
let _ = directionsArray.map { $0.cancel() } mapView.addAnnotation(cologne)
return cologne.coordinate //hard coded coordinates for Cologne
} }
// main function for routing
func getDirections() { func getDirections() {
guard let location = locationManager.location?.coordinate else { guard let location = locationManager.location?.coordinate else {
print("Location not found") //TODO: Inform user we don't have their current location
displayAlert(alertTitle: "Location not found", alertMessage: "App cannot access your location")