diff --git a/CHANGELOG.md b/CHANGELOG.md index 7711ff47559..cab34c3f79b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes to the Mapbox Navigation SDK for iOS +## master + +* `StyleManager.locationFor(styleManager:)` now allows for an optional CLLocation to be returned. [#1523](https://github.com/mapbox/mapbox-navigation-ios/pull/1523) + ## v0.18.1 (June 19, 2018) ### Packaging diff --git a/MapboxNavigation/NavigationViewController.swift b/MapboxNavigation/NavigationViewController.swift index e5160de0e53..5985a347a68 100644 --- a/MapboxNavigation/NavigationViewController.swift +++ b/MapboxNavigation/NavigationViewController.swift @@ -608,16 +608,14 @@ extension NavigationViewController: TunnelIntersectionManagerDelegate { extension NavigationViewController: StyleManagerDelegate { - public func locationFor(styleManager: StyleManager) -> CLLocation { - guard let location = routeController.location else { - if let coordinate = routeController.routeProgress.route.coordinates?.first { - return CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude) - } else { - return CLLocation() - } + public func locationFor(styleManager: StyleManager) -> CLLocation? { + if let location = routeController.location { + return location + } else if let firstCoord = routeController.routeProgress.route.coordinates?.first { + return CLLocation(latitude: firstCoord.latitude, longitude: firstCoord.longitude) + } else { + return nil } - - return location } public func styleManager(_ styleManager: StyleManager, didApply style: Style) { diff --git a/MapboxNavigation/StyleManager.swift b/MapboxNavigation/StyleManager.swift index 5d02f75247f..2c8e4121fb5 100644 --- a/MapboxNavigation/StyleManager.swift +++ b/MapboxNavigation/StyleManager.swift @@ -9,7 +9,7 @@ public protocol StyleManagerDelegate: NSObjectProtocol { /** Asks the delegate for a location to use when calculating sunset and sunrise. */ - @objc func locationFor(styleManager: StyleManager) -> CLLocation + @objc func locationFor(styleManager: StyleManager) -> CLLocation? /** Informs the delegate that a style was applied. diff --git a/MapboxNavigationTests/NavigationViewControllerTests.swift b/MapboxNavigationTests/NavigationViewControllerTests.swift index 1d536b569e0..ec9181eaa46 100644 --- a/MapboxNavigationTests/NavigationViewControllerTests.swift +++ b/MapboxNavigationTests/NavigationViewControllerTests.swift @@ -210,7 +210,7 @@ class NavigationViewControllerTests: XCTestCase { } extension NavigationViewControllerTests: NavigationViewControllerDelegate, StyleManagerDelegate { - func locationFor(styleManager: StyleManager) -> CLLocation { + func locationFor(styleManager: StyleManager) -> CLLocation? { return dependencies.poi.first! } diff --git a/MapboxNavigationTests/StyleManagerTests.swift b/MapboxNavigationTests/StyleManagerTests.swift index 6d395017a90..d5e4083fce9 100644 --- a/MapboxNavigationTests/StyleManagerTests.swift +++ b/MapboxNavigationTests/StyleManagerTests.swift @@ -79,7 +79,7 @@ extension StyleManagerTests: StyleManagerDelegate { func styleManagerDidRefreshAppearance(_ styleManager: StyleManager) { } func styleManager(_ styleManager: StyleManager, didApply style: Style) { } - func locationFor(styleManager: StyleManager) -> CLLocation { + func locationFor(styleManager: StyleManager) -> CLLocation? { return location } }