Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ariba Siddiqui
MapKit Directions
Commits
1377bbc9
Commit
1377bbc9
authored
Nov 29, 2021
by
Ariba Siddiqui
Browse files
Revert "comments for directions and other restructuring"
This reverts commit
05261150
parent
05261150
Changes
8
Hide whitespace changes
Inline
Side-by-side
.DS_Store
View file @
1377bbc9
No preview for this file type
Location Tutorial.xcodeproj/project.pbxproj
View file @
1377bbc9
...
...
@@ -7,6 +7,7 @@
objects
=
{
/* 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 */
;
};
2517A35527502266006F2B81
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2517A35427502266006F2B81
/* AppDelegate.swift */
;
};
2517A35727502266006F2B81
/* SceneDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2517A35627502266006F2B81
/* SceneDelegate.swift */
;
};
...
...
@@ -37,6 +38,7 @@
/* End PBXContainerItemProxy 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>"
;
};
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>"
;
};
...
...
@@ -108,6 +110,7 @@
2517A35D2750226C006F2B81
/* Assets.xcassets */
,
2517A35F2750226C006F2B81
/* LaunchScreen.storyboard */
,
2517A3622750226C006F2B81
/* Info.plist */
,
09AD0D742753EF1C00E400F7
/* MapSerachView.swift */
,
09AD0D762753EF5000E400F7
/* LocationSearch.swift */
,
);
path
=
"Location Tutorial"
;
...
...
@@ -263,6 +266,7 @@
files
=
(
09AD0D772753EF5000E400F7
/* LocationSearch.swift in Sources */
,
2517A35927502266006F2B81
/* ViewController.swift in Sources */
,
09AD0D752753EF1C00E400F7
/* MapSerachView.swift in Sources */
,
2517A35527502266006F2B81
/* AppDelegate.swift in Sources */
,
2517A35727502266006F2B81
/* SceneDelegate.swift in Sources */
,
);
...
...
Location Tutorial.xcodeproj/project.xcworkspace/xcuserdata/aribasiddiqui.xcuserdatad/UserInterfaceState.xcuserstate
View file @
1377bbc9
No preview for this file type
Location Tutorial.xcodeproj/xcuserdata/aribasiddiqui.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
View file @
1377bbc9
...
...
@@ -14,8 +14,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"8
4
"
endingLineNumber =
"8
4
"
startingLineNumber =
"8
6
"
endingLineNumber =
"8
6
"
landmarkName =
"goButtonTapped(_:)"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -30,8 +30,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"10
3
"
endingLineNumber =
"10
3
"
startingLineNumber =
"10
5
"
endingLineNumber =
"10
5
"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -46,8 +46,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"10
4
"
endingLineNumber =
"10
4
"
startingLineNumber =
"10
6
"
endingLineNumber =
"10
6
"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -62,10 +62,58 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"105"
endingLineNumber =
"105"
startingLineNumber =
"107"
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()"
landmarkType =
"7"
>
<Locations>
<Location
uuid =
"298D89E0-B8E7-4739-97A7-7799C4E2704E - 5a8fd180874c388"
shouldBeEnabled =
"Yes"
ignoreCount =
"0"
continueAfterRunningActions =
"No"
symbolName =
"Location_Tutorial.ViewController.getDirections() -> ()"
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<__C.MKDirectionsResponse>, Swift.Optional<Swift.Error>) -> () in Location_Tutorial.ViewController.getDirections() -> ()"
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>
</BreakpointProxy>
<BreakpointProxy
...
...
@@ -78,8 +126,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"11
3
"
endingLineNumber =
"11
3
"
startingLineNumber =
"11
1
"
endingLineNumber =
"11
1
"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -94,8 +142,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"11
9
"
endingLineNumber =
"11
9
"
startingLineNumber =
"11
3
"
endingLineNumber =
"11
3
"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -110,8 +158,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"1
20
"
endingLineNumber =
"1
20
"
startingLineNumber =
"1
14
"
endingLineNumber =
"1
14
"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -126,12 +174,28 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"1
26
"
endingLineNumber =
"1
26
"
startingLineNumber =
"1
19
"
endingLineNumber =
"1
19
"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
</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
BreakpointExtensionID =
"Xcode.Breakpoint.FileBreakpoint"
>
<BreakpointContent
...
...
@@ -142,8 +206,24 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"134"
endingLineNumber =
"134"
startingLineNumber =
"126"
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:)"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -158,8 +238,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"1
35
"
endingLineNumber =
"1
35
"
startingLineNumber =
"1
27
"
endingLineNumber =
"1
27
"
landmarkName =
"createDirectionsRequest(from:)"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -174,12 +254,28 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"1
36
"
endingLineNumber =
"1
36
"
startingLineNumber =
"1
29
"
endingLineNumber =
"1
29
"
landmarkName =
"createDirectionsRequest(from:)"
landmarkType =
"7"
>
</BreakpointContent>
</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
BreakpointExtensionID =
"Xcode.Breakpoint.FileBreakpoint"
>
<BreakpointContent
...
...
@@ -190,8 +286,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"10
8
"
endingLineNumber =
"10
8
"
startingLineNumber =
"1
1
0"
endingLineNumber =
"1
1
0"
landmarkName =
"getDirections()"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -206,8 +302,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"1
72
"
endingLineNumber =
"1
72
"
startingLineNumber =
"1
65
"
endingLineNumber =
"1
65
"
landmarkName =
"mapView(_:rendererFor:)"
landmarkType =
"7"
>
</BreakpointContent>
...
...
@@ -222,8 +318,8 @@
filePath =
"Location Tutorial/ViewController.swift"
startingColumnNumber =
"9223372036854775807"
endingColumnNumber =
"9223372036854775807"
startingLineNumber =
"1
71
"
endingLineNumber =
"1
71
"
startingLineNumber =
"1
64
"
endingLineNumber =
"1
64
"
landmarkName =
"mapView(_:rendererFor:)"
landmarkType =
"7"
>
</BreakpointContent>
...
...
Location Tutorial/Base.lproj/Main.storyboard
View file @
1377bbc9
...
...
@@ -16,7 +16,7 @@
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"414"
height=
"896"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<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"
/>
</mapView>
<button
opaque=
"NO"
contentMode=
"scaleToFill"
fixedFrame=
"YES"
contentHorizontalAlignment=
"center"
contentVerticalAlignment=
"center"
buttonType=
"system"
lineBreakMode=
"middleTruncation"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"ac8-fP-bc3"
>
...
...
Location Tutorial/LocationSearch.swift
View file @
1377bbc9
...
...
@@ -2,6 +2,8 @@
// LocationFinder.swift
// MapKit Testing Search Functionality
//
// Created by Brian Porumb on 25.11.21.
//
import
Foundation
import
Combine
...
...
@@ -9,7 +11,7 @@ import MapKit
class
LocationService
:
NSObject
,
ObservableObject
{
// Differ
e
nt search states
// Differnt search states
enum
LocationStatus
:
Equatable
{
case
idle
case
noResults
...
...
Location Tutorial/MapSe
a
rchView.swift
→
Location Tutorial/MapSer
a
chView.swift
View file @
1377bbc9
//
//
MapSearch
View.swift
//
Content
View.swift
// MapKit Testing Search Functionality
//
// Created by Brian Porumb on 25.11.21.
//
import
SwiftUI
...
...
Location Tutorial/ViewController.swift
View file @
1377bbc9
//
// ViewController.swift
// MapKit Routing, Annotations and Location
// Location Tutorial
//
// Created by Huang on 2021/11/25.
//
import
UIKit
...
...
@@ -12,31 +14,26 @@ class ViewController: UIViewController {
@IBOutlet
weak
var
mapView
:
MKMapView
!
let
locationManager
=
CLLocationManager
()
var
regionInMeters
:
Double
=
10000
//scale of the map
// ### code for directions start ###
var
directionsArray
:
[
MKDirections
]
=
[]
// ### code for directions end ###
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
checkLocationServices
()
setupMapView
()
}
func
setupMapView
(){
mapView
.
delegate
=
self
}
func
setupLocationManager
()
{
locationManager
.
delegate
=
self
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
()
{
if
let
location
=
locationManager
.
location
?
.
coordinate
{
let
region
=
MKCoordinateRegion
.
init
(
center
:
location
,
latitudinalMeters
:
regionInMeters
,
longitudinalMeters
:
regionInMeters
)
...
...
@@ -44,18 +41,18 @@ class ViewController: UIViewController {
}
}
// check if user's location services are enabled
func
checkLocationServices
()
{
if
CLLocationManager
.
locationServicesEnabled
()
{
setupLocationManager
()
checkLocationAuthorization
()
}
else
{
print
(
"Location Services are not enabled"
)
displayAlert
(
alertTitle
:
"Location Services are not turned on"
,
alertMessage
:
"You must enable your Location Services to perform this action"
)
// Show alert letting the user know they have to turn this on.
}
}
// checking authorization status
func
checkLocationAuthorization
()
{
let
manager
=
CLLocationManager
()
switch
manager
.
authorizationStatus
{
...
...
@@ -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
)
{
print
(
"GO button tapped"
)
getDirections
()
}
//to prevent throttling and multiple renders
func
resetMapView
(
withNew
directions
:
MKDirections
)
{
mapView
.
removeOverlays
(
mapView
.
overlays
)
directionsArray
.
append
(
directions
)
let
_
=
directionsArray
.
map
{
$0
.
cancel
()
}
func
getLocationCoordinates
()
->
CLLocationCoordinate2D
{
let
cologne
=
MKPointAnnotation
()
cologne
.
title
=
"Cologne"
cologne
.
coordinate
=
CLLocationCoordinate2D
(
latitude
:
50.9375
,
longitude
:
6.9603
)
mapView
.
addAnnotation
(
cologne
)
return
cologne
.
coordinate
//hard coded coordinates for Cologne
}
// main function for routing
func
getDirections
()
{
guard
let
location
=
locationManager
.
location
?
.
coordinate
else
{
print
(
"Location not found"
)
displayAlert
(
alertTitle
:
"Location not found"
,
alertMessage
:
"App cannot access your location"
)
//TODO: Inform user we don't have their current location
return
}
...
...
@@ -105,21 +107,12 @@ class ViewController: UIViewController {
resetMapView
(
withNew
:
directions
)
directions
.
calculate
{
[
unowned
self
]
(
response
,
error
)
in
if
error
!=
nil
{
print
(
"Directions couldn't be computed"
)
displayAlert
(
alertTitle
:
"Directions couldn't be computed"
,
alertMessage
:
"App cannot find directions to the destination"
)
return
}
guard
let
response
=
response
else
{
print
(
"Response not found"
)
displayAlert
(
alertTitle
:
"Directions couldn't be computed"
,
alertMessage
:
"App cannot find directions to the destination"
)
return
}
//TODO: Handle error if needed
guard
let
response
=
response
else
{
return
}
//TODO: Show response not available in an alert
print
(
"total routes found:
\(
response
.
routes
.
count
)
"
)
for
route
in
response
.
routes
{
self
.
mapView
.
addOverlay
(
route
.
polyline
,
level
:
.
aboveRoads
)
//add an overlay for each route
//polyline: connected line segments that don't form a loop
var
directionsRegion
:
MKCoordinateRegion
=
MKCoordinateRegion
.
init
(
route
.
polyline
.
boundingMapRect
)
// recenter
self
.
mapView
.
addOverlay
(
route
.
polyline
,
level
:
.
aboveRoads
)
var
directionsRegion
:
MKCoordinateRegion
=
MKCoordinateRegion
.
init
(
route
.
polyline
.
boundingMapRect
)
//to increase the span of the region in order to add some margin
directionsRegion
.
span
.
latitudeDelta
*=
1.2
directionsRegion
.
span
.
longitudeDelta
*=
1.2
...
...
@@ -128,30 +121,31 @@ class ViewController: UIViewController {
}
}
// creates a new request by configuring different properties
func
createDirectionsRequest
(
from
coordinate
:
CLLocationCoordinate2D
)
->
MKDirections
.
Request
{
let
destinationCoordinate
=
getLocationCoordinates
()
let
startingLocation
=
MKPlacemark
(
coordinate
:
coordinate
)
//user's location
let
destination
=
MKPlacemark
(
coordinate
:
destinationCoordinate
)
let
request
=
MKDirections
.
Request
()
request
.
source
=
MKMapItem
(
placemark
:
startingLocation
)
request
.
destination
=
MKMapItem
(
placemark
:
destination
)
request
.
transportType
=
.
automobile
request
.
requestsAlternateRoutes
=
true
return
request
}
// hard-coded to return coordinates of Southampton
func
getLocationCoordinates
()
->
CLLocationCoordinate2D
{
let
cologne
=
MKPointAnnotation
()
cologne
.
title
=
"Southampton"
cologne
.
coordinate
=
CLLocationCoordinate2D
(
latitude
:
50.9097
,
longitude
:
-
1.4044
)
mapView
.
addAnnotation
(
cologne
)
// add annotation(a pin) for Southampton
return
cologne
.
coordinate
//to prevent throttling and multiple renders
func
resetMapView
(
withNew
directions
:
MKDirections
)
{
mapView
.
removeOverlays
(
mapView
.
overlays
)
directionsArray
.
append
(
directions
)
let
_
=
directionsArray
.
map
{
$0
.
cancel
()
}
}
// ### code for directions end ###
}
extension
ViewController
:
CLLocationManagerDelegate
,
MKMapViewDelegate
{
func
locationManager
(
_
manager
:
CLLocationManager
,
didUpdateLocations
locations
:
[
CLLocation
])
{
...
...
@@ -164,8 +158,7 @@ extension ViewController: CLLocationManagerDelegate, MKMapViewDelegate {
checkLocationAuthorization
()
}
// called each time the bounding map rectangle of an overlay intersects the visible region of a map
// defines 'how' the overlay should look like -> renderer properties are specified here
// ### code for directions start ###
func
mapView
(
_
mapView
:
MKMapView
,
rendererFor
overlay
:
MKOverlay
)
->
MKOverlayRenderer
{
let
renderer
=
MKPolylineRenderer
(
overlay
:
overlay
)
...
...
@@ -175,22 +168,22 @@ extension ViewController: CLLocationManagerDelegate, MKMapViewDelegate {
return
renderer
}
// Delegate method for annotations
func
mapView
(
_
mapView
:
MKMapView
,
viewFor
annotation
:
MKAnnotation
)
->
MKAnnotationView
?
{
guard
annotation
is
MKPointAnnotation
else
{
return
nil
}
let
identifier
=
"Annotation"
// dequeue an existing annotation view before creating a new one as new annotations move on-screen
// (performance enhancement)
var
annotationView
=
mapView
.
dequeueReusableAnnotationView
(
withIdentifier
:
identifier
)
if
annotationView
==
nil
{
annotationView
=
MKPinAnnotationView
(
annotation
:
annotation
,
reuseIdentifier
:
identifier
)
annotationView
!.
canShowCallout
=
true
}
else
{
annotationView
!.
annotation
=
annotation
}
return
annotationView
}
// ### code for directions end ###
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment