Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add waypoint handling #270

Merged
merged 71 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
92a1d30
Add waypoint handling
Jun 8, 2017
d009fff
more waypoints
Jun 9, 2017
c33b154
Use sections
Jun 9, 2017
c6dabb3
clear map
Jun 11, 2017
2c6524a
remove destination
Jun 13, 2017
382ede6
Updates
Jun 13, 2017
52b867d
remove
Jun 13, 2017
315a681
use name
Jun 16, 2017
cbe2ce1
return waypoint when arriving at each waypoint
Jun 19, 2017
988dfd0
Merge branch 'master' into waypoints
Jun 20, 2017
753814a
update
Jun 20, 2017
275b973
Merge branch 'master' into waypoints
Jul 6, 2017
13b4ad1
update example
Jul 6, 2017
ebfa33f
Merge branch 'master' into waypoints
Jul 25, 2017
204eeff
update
Jul 25, 2017
85684aa
remove arg
Jul 26, 2017
e88e2b1
localize
Jul 26, 2017
d7828aa
remove comma
Jul 27, 2017
9f10ad9
Merge branch 'master' into waypoints
Jul 27, 2017
082c44e
whitespace
Jul 31, 2017
40d58cd
fix
Jul 31, 2017
2c26fe9
whitespace
Jul 31, 2017
6340c58
Merge branch 'master' into waypoints
Jul 31, 2017
f052af0
Style, confirm next
Jul 31, 2017
0ab7e26
move
Jul 31, 2017
3e95e9c
remove unused
Jul 31, 2017
8eb79fa
Merge branch 'master' into waypoints
Aug 3, 2017
ee9df0f
Remove waypoint once done
Aug 4, 2017
bb73e66
Merge branch 'master' into waypoints
Aug 7, 2017
edd881b
add clear button
Aug 7, 2017
b0247d6
Merge branch 'master' into waypoints
Aug 8, 2017
4369010
Make waypoint customizable
Aug 9, 2017
3c568c4
fix
Aug 9, 2017
f0ab02f
Improve names
Aug 9, 2017
0c5ae6f
Add back
Aug 9, 2017
cfa67b6
add back
Aug 9, 2017
7144f59
move around
Aug 9, 2017
087de57
remove
Aug 9, 2017
7b15853
remove
Aug 9, 2017
ba54bd0
Merge branch 'master' into waypoints
Aug 9, 2017
4934ad0
move arrow
Aug 9, 2017
84c3c41
add back
Aug 9, 2017
2f5602f
Merge branch 'master' into waypoints
Aug 10, 2017
8b41be7
Change names
Aug 10, 2017
5907c9a
Add translation
Aug 10, 2017
3f0e8ca
Wow, rename
Aug 10, 2017
deda53a
Update
Aug 10, 2017
20bc71e
increment
Aug 10, 2017
3f8214f
False
Aug 10, 2017
4305493
Add translation, update
Aug 11, 2017
b2562d6
fix
Aug 11, 2017
cb66468
Merge branch 'master' into waypoints
Aug 11, 2017
a1d4cbe
Merge branch 'master' into waypoints
Aug 14, 2017
8e17b03
change api
Aug 14, 2017
771dbca
remove
Aug 14, 2017
5b66ffd
Merge branch 'master' into waypoints
Aug 14, 2017
5ebb998
document
Aug 14, 2017
e177cd2
Consistent
Aug 14, 2017
1ab08d5
Merge branch 'master' into waypoints
Aug 16, 2017
1286a2e
remove annotations
Aug 16, 2017
9b2f21b
Merge branch 'master' into waypoints
Aug 17, 2017
306e55a
Merge branch 'master' into waypoints
Aug 17, 2017
518d535
Merge branch 'master' into waypoints
Aug 21, 2017
8ef4112
Merge branch 'master' into waypoints
Aug 22, 2017
f0dc3d5
Merge branch 'master' into waypoints
Aug 23, 2017
e5eb660
Always update
Aug 23, 2017
b9b3555
Flip
Aug 24, 2017
84a1f34
Update
Aug 24, 2017
de69c03
Make bolder
Aug 24, 2017
5995b2f
darker gray
Aug 24, 2017
26fec4b
Update docs
Aug 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 3.5
github "mapbox/MapboxDirections.swift" ~> 0.9.0
github "mapbox/MapboxDirections.swift" "d18561afc477bdd6e844020725c8b9eadf0ffd12"
github "52inc/Pulley" ~> 1.3.1
github "rs/SDWebImage" ~> 4.0
github "Project-OSRM/osrm-text-instructions.swift" ~> 0.1.2
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ github "52inc/Pulley" "1.4"
github "Project-OSRM/osrm-text-instructions.swift" "v0.1.2"
github "facebook/ios-snapshot-test-case" "2.1.4"
github "frederoni/aws-sdk-ios" "40c7d5d60e0b80d70cd1502ef0cf8507f023f8d5"
github "mapbox/MapboxDirections.swift" "v0.9.1"
github "mapbox/MapboxDirections.swift" "d18561afc477bdd6e844020725c8b9eadf0ffd12"
github "raphaelmor/Polyline" "v4.1.1"
github "rs/SDWebImage" "4.0.0"
25 changes: 25 additions & 0 deletions Examples/Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oWT-TG-jZs">
<rect key="frame" x="0.0" y="623" width="375" height="44"/>
<color key="backgroundColor" white="1" alpha="0.60000002379999995" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="MXR-Fb-48J"/>
</constraints>
<state key="normal" title="Get Route"/>
<connections>
<action selector="didTapGetRoute:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ffn-fF-Lba"/>
</connections>
</button>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="p1Q-wj-seE">
<rect key="frame" x="8" y="565" width="70" height="30"/>
<state key="normal" title="Clear map"/>
<connections>
<action selector="didTapClearmap:" destination="BYZ-38-t0r" eventType="touchUpInside" id="YbJ-3h-xu2"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
Expand All @@ -64,8 +82,13 @@
<constraint firstAttribute="bottom" secondItem="8Sl-bV-xyU" secondAttribute="bottom" id="LOb-l9-Iql"/>
<constraint firstItem="8Sl-bV-xyU" firstAttribute="width" secondItem="A3N-JT-loC" secondAttribute="width" multiplier="1:2" id="Pds-uP-zSB"/>
<constraint firstAttribute="trailing" secondItem="KIU-cH-IXd" secondAttribute="trailing" id="Q7E-HM-WIz"/>
<constraint firstItem="oWT-TG-jZs" firstAttribute="top" secondItem="p1Q-wj-seE" secondAttribute="bottom" constant="28" id="SbN-yI-sn0"/>
<constraint firstAttribute="trailing" secondItem="oWT-TG-jZs" secondAttribute="trailing" id="TC4-VU-ggG"/>
<constraint firstAttribute="bottom" secondItem="KIU-cH-IXd" secondAttribute="bottom" id="TjN-pb-n3K"/>
<constraint firstItem="p1Q-wj-seE" firstAttribute="leading" secondItem="A3N-JT-loC" secondAttribute="leading" constant="8" id="djs-kC-Hft"/>
<constraint firstItem="8Sl-bV-xyU" firstAttribute="leading" secondItem="A3N-JT-loC" secondAttribute="leading" id="dsN-v1-DQf"/>
<constraint firstAttribute="bottom" secondItem="oWT-TG-jZs" secondAttribute="bottom" id="e7k-3v-zuf"/>
<constraint firstItem="oWT-TG-jZs" firstAttribute="leading" secondItem="A3N-JT-loC" secondAttribute="leading" id="gH1-mU-Ajg"/>
<constraint firstItem="KIU-cH-IXd" firstAttribute="leading" secondItem="8Sl-bV-xyU" secondAttribute="trailing" id="q92-IP-Nlc"/>
<constraint firstAttribute="trailing" secondItem="Hk0-SM-2Wl" secondAttribute="trailing" id="qaa-r0-NSw"/>
<constraint firstItem="Hk0-SM-2Wl" firstAttribute="leading" secondItem="A3N-JT-loC" secondAttribute="leading" id="vRW-UT-mQD"/>
Expand Down Expand Up @@ -98,6 +121,8 @@
</constraints>
</view>
<connections>
<outlet property="clearMapButton" destination="p1Q-wj-seE" id="ULz-0n-Sys"/>
<outlet property="getRouteButton" destination="oWT-TG-jZs" id="b4W-Xb-oB7"/>
<outlet property="howToBeginLabel" destination="Hk0-SM-2Wl" id="iU7-G1-DBc"/>
<outlet property="mapView" destination="A3N-JT-loC" id="iZS-hq-X5f"/>
<outlet property="simulateNavigationButton" destination="KIU-cH-IXd" id="Bdk-oG-55B"/>
Expand Down
55 changes: 41 additions & 14 deletions Examples/Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ let layerIdentifier = "layerIdentifier"

class ViewController: UIViewController, MGLMapViewDelegate, NavigationViewControllerDelegate, NavigationMapViewDelegate {

var destination: MGLPointAnnotation?
var navigation: RouteController?
var userRoute: Route?
var waypoints: [Waypoint] = []

@IBOutlet weak var mapView: NavigationMapView!
@IBOutlet weak var startNavigationButton: UIButton!
@IBOutlet weak var simulateNavigationButton: UIButton!
@IBOutlet weak var howToBeginLabel: UILabel!

@IBOutlet weak var getRouteButton: UIButton!
@IBOutlet weak var clearMapButton: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -41,21 +42,42 @@ class ViewController: UIViewController, MGLMapViewDelegate, NavigationViewContro
return
}

if let destination = destination {
mapView.removeAnnotation(destination)
}
let coordinates = mapView.convert(sender.location(in: mapView), toCoordinateFrom: mapView)

destination = MGLPointAnnotation()
destination?.coordinate = mapView.convert(sender.location(in: mapView), toCoordinateFrom: mapView)
mapView.addAnnotation(destination!)
howToBeginLabel.isHidden = true
getRouteButton.isHidden = false
clearMapButton.isHidden = false

getRoute()
let annotation = MGLPointAnnotation()
annotation.coordinate = coordinates
mapView.addAnnotation(annotation)

let waypoint = Waypoint(coordinate: coordinates)
waypoint.coordinateAccuracy = -1
waypoints.append(waypoint)
}

@IBAction func didTapStartNavigation(_ sender: Any) {
startNavigation(along: userRoute!)
}

@IBAction func didTapClearmap(_ sender: Any) {
mapView.removeAnnotations(mapView.annotations ?? [])

startNavigationButton.isHidden = true
simulateNavigationButton.isHidden = true
getRouteButton.isHidden = true
clearMapButton.isHidden = true
howToBeginLabel.isHidden = false

waypoints.removeAll()
mapView.removeRoute()
}

@IBAction func didTapGetRoute(_ sender: Any) {
getRoute()
}

@IBAction func didTapSimulateNavigation(_ sender: Any) {
startNavigation(along: userRoute!, simulatesLocationUpdates: true)
}
Expand Down Expand Up @@ -104,26 +126,31 @@ class ViewController: UIViewController, MGLMapViewDelegate, NavigationViewContro
}

func getRoute(didFinish: (()->())? = nil) {
guard let destination = destination else { return }

let userWaypoint = Waypoint(location: mapView.userLocation!.location!, heading: mapView.userLocation?.heading, name: "user")
userWaypoint.coordinateAccuracy = -1
waypoints.insert(userWaypoint, at: 0)

let options = RouteOptions(coordinates: [mapView.userLocation!.coordinate, destination.coordinate])
let options = RouteOptions(waypoints: waypoints)
options.includesSteps = true
options.routeShapeResolution = .full
options.profileIdentifier = .automobileAvoidingTraffic

_ = Directions.shared.calculate(options) { [weak self] (waypoints, routes, error) in
guard error == nil else {
print(error!)
print(error!.localizedDescription)
return
}
guard let route = routes?.first else {
print("No routes")
return
}

self?.userRoute = route
self?.startNavigationButton.isHidden = false
self?.simulateNavigationButton.isHidden = false
self?.howToBeginLabel.isHidden = true
self?.getRouteButton.isHidden = true

// Open method for adding and updating the route line
self?.mapView.showRoute(route)
Expand Down Expand Up @@ -252,7 +279,7 @@ class ViewController: UIViewController, MGLMapViewDelegate, NavigationViewContro
return line
}

func navigationViewController(_ navigationViewController: NavigationViewController, didArriveAt destination: MGLAnnotation) {
print("User arrived at \(destination)")
func navigationViewController(_ navigationViewController: NavigationViewController, didArriveAt destination: Waypoint) {
print("User arrived at \(destination.name ?? "waypoint")")
}
}
12 changes: 10 additions & 2 deletions MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ extension RouteController: CLLocationManagerDelegate {
let userSnapToStepDistanceFromManeuver = distance(along: routeProgress.currentLegProgress.currentStep.coordinates!, from: location.coordinate)
let secondsToEndOfStep = userSnapToStepDistanceFromManeuver / location.speed

guard routeProgress.currentLegProgress.alertUserLevel != .arrive else {
guard routeProgress.currentLegProgress.alertUserLevel != .arrive,
routeProgress.remainingWaypoints.count > 0 else {
// Don't advance nor check progress if the user has arrived at their destination
suspendLocationUpdates()
NotificationCenter.default.post(name: RouteControllerProgressDidChange, object: self, userInfo: [
Expand Down Expand Up @@ -257,7 +258,9 @@ extension RouteController: CLLocationManagerDelegate {
}

if routeProgress.currentLegProgress.alertUserLevel != newlyCalculatedAlertLevel {

routeProgress.currentLegProgress.alertUserLevel = newlyCalculatedAlertLevel

// Use fresh user location distance to end of step
// since the step could of changed
let userDistance = distance(along: routeProgress.currentLegProgress.currentStep.coordinates!, from: location.coordinate)
Expand All @@ -266,6 +269,12 @@ extension RouteController: CLLocationManagerDelegate {
RouteControllerAlertLevelDidChangeNotificationRouteProgressKey: routeProgress,
RouteControllerAlertLevelDidChangeNotificationDistanceToEndOfManeuverKey: userDistance
])

if routeProgress.currentLegProgress.alertUserLevel == .arrive,
routeProgress.remainingWaypoints.count > 1 {
routeProgress.legIndex += 1
routeProgress.currentLegProgress.alertUserLevel = .depart
}
}
}

Expand All @@ -285,7 +294,6 @@ extension RouteController: CLLocationManagerDelegate {
routeTask?.cancel()

let options = routeProgress.route.routeOptions

options.waypoints = [Waypoint(coordinate: location.coordinate)] + routeProgress.remainingWaypoints

if let firstWaypoint = options.waypoints.first, location.course >= 0 {
Expand Down
2 changes: 0 additions & 2 deletions MapboxCoreNavigation/RouteProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ open class RouteProgress: NSObject {
}
}


/**
If waypoints are provided in the `Route`, this will contain which leg the user is on.
*/
Expand Down Expand Up @@ -108,7 +107,6 @@ open class RouteProgress: NSObject {
}

public var currentLegProgress: RouteLegProgress!


public init(route: Route, legIndex: Int = 0) {
self.route = route
Expand Down
4 changes: 0 additions & 4 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
351BEC061E5BCC6C006FE110 /* ManeuverDirection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC041E5BCC6C006FE110 /* ManeuverDirection.swift */; };
351BEC0D1E5BCC72006FE110 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC081E5BCC72006FE110 /* Bundle.swift */; };
351BEC0E1E5BCC72006FE110 /* DashedLineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC091E5BCC72006FE110 /* DashedLineView.swift */; };
351BEC0F1E5BCC72006FE110 /* Directions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC0A1E5BCC72006FE110 /* Directions.swift */; };
351BEC101E5BCC72006FE110 /* DistanceFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC0B1E5BCC72006FE110 /* DistanceFormatter.swift */; };
351BEC291E5BD530006FE110 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 351BEC281E5BD530006FE110 /* Assets.xcassets */; };
351BEC2B1E5BD538006FE110 /* Shields.plist in Resources */ = {isa = PBXBuildFile; fileRef = 351BEC2A1E5BD538006FE110 /* Shields.plist */; };
Expand Down Expand Up @@ -267,7 +266,6 @@
351BEC041E5BCC6C006FE110 /* ManeuverDirection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManeuverDirection.swift; sourceTree = "<group>"; };
351BEC081E5BCC72006FE110 /* Bundle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
351BEC091E5BCC72006FE110 /* DashedLineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashedLineView.swift; sourceTree = "<group>"; };
351BEC0A1E5BCC72006FE110 /* Directions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Directions.swift; sourceTree = "<group>"; };
351BEC0B1E5BCC72006FE110 /* DistanceFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DistanceFormatter.swift; sourceTree = "<group>"; };
351BEC281E5BD530006FE110 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Resources/Assets.xcassets; sourceTree = "<group>"; };
351BEC2A1E5BD538006FE110 /* Shields.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Shields.plist; path = Resources/Shields.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -584,7 +582,6 @@
children = (
C5000A921EC25C6E00563EA9 /* Abbreviations.swift */,
351BEC081E5BCC72006FE110 /* Bundle.swift */,
351BEC0A1E5BCC72006FE110 /* Directions.swift */,
C55CEB271EB7E4240065D7D9 /* Locale.swift */,
351BEC041E5BCC6C006FE110 /* ManeuverDirection.swift */,
351BEBDF1E5BCC63006FE110 /* MGLMapView.swift */,
Expand Down Expand Up @@ -1098,7 +1095,6 @@
C5000A931EC25C6E00563EA9 /* Abbreviations.swift in Sources */,
35C9973F1E732C1B00544D1C /* RouteVoiceController.swift in Sources */,
351BEBFC1E5BCC63006FE110 /* NavigationViewController.swift in Sources */,
351BEC0F1E5BCC72006FE110 /* Directions.swift in Sources */,
35C997411E732C5400544D1C /* RouteStepFormatter.swift in Sources */,
351BEBFB1E5BCC63006FE110 /* RouteTableViewHeaderView.swift in Sources */,
35EC316D1EA64057004280F5 /* SimulatedRoute.swift in Sources */,
Expand Down
21 changes: 0 additions & 21 deletions MapboxNavigation/Directions.swift

This file was deleted.

Loading