Skip to content

Commit

Permalink
Merge pull request #71 from situmtech/release/0.2.0
Browse files Browse the repository at this point in the history
Release/0.2.0
  • Loading branch information
fsvilas committed Feb 21, 2022
2 parents 16955a5 + 2b3335a commit 91c245d
Show file tree
Hide file tree
Showing 17 changed files with 431 additions and 85 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ Carthage/Build
# `pod install` in .travis.yml
#
Example/Pods/

# documentation build path
docs/
*.zip
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
All non released changes should be in CHANGELOG_UNRELEASED.md file

---------
## [0.2.0] - 2022-02-21
### Added
* Added protocol OnNavigationListener and a method setOnNavigationListener on SitumMapsLibrary. As a developer you can
set a listener and implement the protocol methods to get notified of events during navigation (onNavigationRequested,
onNavigationError and onNavigationFinished). Each of the protocol methods will receive an object that complies to
protocol Navigation.
* Added protocol Navigation that holds information about the current status of the navigation and the navigation
destination.

## [0.1.22] - 2022-02-21
# Added
* Added method navigateToLocation(floor, lat, lng) on SitumMapLibrary to navigate to a location in the current building.
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PODS:
- SitumSDK (2.52.0):
- Protobuf (~> 3.7)
- SSZipArchive (~> 2.4)
- SitumWayfinding (0.1.22):
- SitumWayfinding (0.2.0):
- GoogleMaps (~> 4.2.0)
- SitumSDK (~> 2.52.0)
- SSZipArchive (2.4.3)
Expand All @@ -31,9 +31,9 @@ SPEC CHECKSUMS:
GoogleMaps: eb03e327edfd70b06de1e6e321653f73712df7ad
Protobuf: 235750e4696ff59fb07d949a9dbbc92b3c0700fe
SitumSDK: cc0a5b48a90669c463622b12ae6f07588863f5af
SitumWayfinding: 9f56c9004b7136580ab154830c758416fb977919
SitumWayfinding: 5a7a574f799580866b751b57522a224b04fa8ec6
SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef

PODFILE CHECKSUM: 181eb894514efe3e0119ec84dae5349934aaaa20

COCOAPODS: 1.11.2
COCOAPODS: 1.10.2
2 changes: 1 addition & 1 deletion Example/SitumWayfinding/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ViewController: UIViewController {
action = .navigateToLocation(floor: floor, lat: lat, lng: lng)
self.performSegue(withIdentifier: "loadWayfindingSegue", sender: self)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "loadWayfindingSegue" {
if let vc = segue.destination as? WayfindingController {
Expand Down
34 changes: 28 additions & 6 deletions Example/SitumWayfinding/WayfindingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SitumWayfinding
import SitumSDK
import GoogleMaps

class WayfindingController: UIViewController, OnPoiSelectionListener, OnFloorChangeListener, OnMapReadyListener {
class WayfindingController: UIViewController {

@IBOutlet var containerView: UIView!

Expand Down Expand Up @@ -45,6 +45,7 @@ class WayfindingController: UIViewController, OnPoiSelectionListener, OnFloorCha
self.library?.setOnPoiSelectionListener(listener: self)
self.library?.setOnFloorChangeListener(listener: self)
self.library?.setOnMapReadyListener(listener: self)
self.library?.setOnNavigationListener(listener: self)

do {
try self.library!.load()
Expand All @@ -58,19 +59,26 @@ class WayfindingController: UIViewController, OnPoiSelectionListener, OnFloorCha
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

// MARK: Wayfinding Delegate
}

// MARK: Wayfinding Delegates
extension WayfindingController: OnPoiSelectionListener {
func onPoiDeselected(building: SITBuilding) {
print("onPoiDeselected app")
}

func onPoiSelected(poi: SITPOI, level: SITFloor, building: SITBuilding) {
print("onPoiSelected")
}
}

extension WayfindingController: OnFloorChangeListener {
func onFloorChanged(from: SITFloor, to: SITFloor, building: SITBuilding) {
print("onFloorChanged from \(from.floor) to \(to.floor)")
}
}

extension WayfindingController: OnMapReadyListener {
func onMapReady(map: SitumMap) {
print("map ready to interact \(map)")

Expand Down Expand Up @@ -102,13 +110,27 @@ class WayfindingController: UIViewController, OnPoiSelectionListener, OnFloorCha
switch error {
case .invalidPOI:
print("POI: selection error, invalid POI \(error))")
case .unknown:
print("POI: unknown error \(error))")
default:
print("POI: wayfinding error \(error)")
}
} else {
print("POI: generic error \(error))")
}
}
}

extension WayfindingController: OnNavigationListener {
func onNavigationRequested(navigation: Navigation) {
print("Navigation: starts with destination \(navigation.destination)")
}

func onNavigationError(navigation: Navigation, error: Error) {
print("Navigation: to \(navigation.destination) fails with error \(error)")
}

func onNavigationFinished(navigation: Navigation) {
print("Navigation: finished with status \(navigation.status)")
}
}


2 changes: 1 addition & 1 deletion SitumWayfinding.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SitumWayfinding'
s.version = '0.1.22'
s.version = '0.2.0'
s.summary = 'Indoor Location for iOS.'
s.static_framework = true

Expand Down
93 changes: 33 additions & 60 deletions SitumWayfinding/Classes/Positioning/PositioningPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ import Foundation
import SitumSDK
import GoogleMaps

enum SITDirectionsRequestValidity{
case SITValidDirectionsRequest
case SITNotOriginError
case SITOutdorOriginError
case SITNotDestinationError
}

class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate, SITNavigationDelegate {

var view: PositioningView?
Expand Down Expand Up @@ -83,12 +76,12 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate
self.locationManagerUserLocation = nil
self.lastOOBAlert = 0.0
self.lastCalibrationAlert = 0.0
view?.stop()
view?.cleanLocationUI()
view?.stopNavigation(status: .canceled)
}
func stopNavigation() {

func resetLastOutsideRouteAlert() {
self.lastOutsideRouteAlert = 0.0
view?.stopNavigation()
}

public func shouldShowFakeLocSelector() -> Bool {
Expand Down Expand Up @@ -275,16 +268,15 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate
}

public func requestDirections(to position: SITPoint!) {
let directionsRequestValidity = checkDirectionsRequestValidity(origin: userLocation?.position ?? nil, destination: position)
if (directionsRequestValidity == .SITValidDirectionsRequest){
var request: SITDirectionsRequest = RequestBuilder.buildDirectionsRequest(userLocation: userLocation!, destination: position)
request = self.interceptorsManager.onDirectionsRequest(request)
SITDirectionsManager.sharedInstance().delegate = self
SITDirectionsManager.sharedInstance().requestDirections(request)
}else{
view?.stopNavigation()
self.alertUserOfInvalidDirectionsRequest(error: directionsRequestValidity)
if let navigationError = checkDirectionsRequestValidity(origin: userLocation?.position ?? nil, destination: position) {
view?.stopNavigation(status: .error(navigationError))
return
}

var request: SITDirectionsRequest = RequestBuilder.buildDirectionsRequest(userLocation: userLocation!, destination: position)
request = self.interceptorsManager.onDirectionsRequest(request)
SITDirectionsManager.sharedInstance().delegate = self
SITDirectionsManager.sharedInstance().requestDirections(request)
}

func isUserIndoor() -> Bool{
Expand All @@ -298,47 +290,32 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate
return SITNavigationManager.shared().isRunning()
}

func checkDirectionsRequestValidity(origin: SITPoint!, destination: SITPoint!) -> SITDirectionsRequestValidity{
let originValidity = checkDirectionsRequestOriginValidity(origin: origin)
let destinationValidity = self.checkDirectionsRequestDestinationValidity(destination: destination)
if (originValidity != .SITValidDirectionsRequest){
return originValidity
}
return destinationValidity
}

func alertUserOfInvalidDirectionsRequest(error: SITDirectionsRequestValidity){
switch error {
case .SITNotOriginError:
view?.showAlertMessage(title: "Position unknown", message: "User actual location is unknown, please activate the positioning before computing a route and try again.", alertType: .otherAlert)
case .SITOutdorOriginError:
view?.showAlertMessage(title: "Position outdoor", message: "User actual location is outdoor, navegation is only avaialble indoor.", alertType: .otherAlert)
case .SITNotDestinationError:
view?.showAlertMessage(title: "No destination selected", message: "There is no destination currently selected, the navigation cannot be started. Please select a POI (or longpress to create a custom one) and try again.", alertType: .otherAlert)
case .SITValidDirectionsRequest:
//No need to do anything
break
func checkDirectionsRequestValidity(origin: SITPoint!, destination: SITPoint!) -> NavigationError? {
let originError = checkIfOriginIsValid(origin: origin)
if (originError != nil){
return originError
}

let destinationError = self.checkIfDestinationIsValid(destination: destination)
return destinationError
}

func checkDirectionsRequestOriginValidity(origin:SITPoint!) -> SITDirectionsRequestValidity{
func checkIfOriginIsValid(origin:SITPoint!) -> NavigationError? {
if (origin == nil){
//Theoretically this shouldnt happen as positioning is started when a route is requested if it was stopped
return .SITNotOriginError;
return .positionUnknown
}
if (origin.isOutdoor()) {
return .SITOutdorOriginError;
return .outdoorOrigin
}
return .SITValidDirectionsRequest

return nil
}

func checkDirectionsRequestDestinationValidity(destination: SITPoint!) -> SITDirectionsRequestValidity{
func checkIfDestinationIsValid(destination: SITPoint!) -> NavigationError? {
if (destination == nil){
return .SITNotDestinationError
return .noDestinationSelected
}
return .SITValidDirectionsRequest
return nil
}

func requestNavigation(route: SITRoute) {
Expand Down Expand Up @@ -392,8 +369,8 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate

func locationManager(_ locationManager: SITLocationInterface, didFailWithError error: Error?) {
Logger.logErrorMessage("Location error problem: \(error.debugDescription)")
view?.stop()
view?.showAlertMessage(title: "Error", message: error!.localizedDescription, alertType: .otherAlert)
view?.cleanLocationUI()
view?.stopNavigation(status: .error(NavigationError.locationError(error)))
}

func locationManager(_ locationManager: SITLocationInterface, didUpdate state: SITLocationState) {
Expand All @@ -415,7 +392,7 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate
case .userNotInBuilding:
stateName = "User not in building"
if isUserNavigating(){
view?.stopNavigation()
view?.stopNavigation(status: .error(NavigationError.outsideBuilding))
}
showAlertIfNeeded(type: .outOfBuilding, title: self.oobAlertTitle, message: "The user is currently outside of the building. Positioning will resume when the user returns.")
break;
Expand All @@ -426,16 +403,14 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate
//MARK: DirectionsDelegate methods

func directionsManager(_ manager: SITDirectionsInterface, didFailProcessingRequest request: SITDirectionsRequest, withError error: Error?) {
view?.showAlertMessage(title: "Unable to compute route", message: "An unexpected error was found while computing the route. Please try again.", alertType: .otherAlert)
Logger.logErrorMessage("directions request failed with error: \(error.debugDescription)");
self.stopNavigation()
self.view?.stopNavigation(status: .error(NavigationError.unableToComputeRoute))
}

func directionsManager(_ manager: SITDirectionsInterface, didProcessRequest request: SITDirectionsRequest, withResponse route: SITRoute) {
if (route.routeSteps.count == 0) {
view?.showAlertMessage(title: "Unable to compute route", message: "There is no route between the selected locations. Try to compute a different route or to switch accessibility mode", alertType: .otherAlert)
Logger.logDebugMessage("Unable to find a path for request: \(request.debugDescription)")
self.stopNavigation()
self.view?.stopNavigation(status: .error(NavigationError.noAvailableRoute))
} else {
view?.showRoute(route: route)
self.directionsRequest = request
Expand All @@ -449,7 +424,7 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate

func navigationManager(_ navigationManager: SITNavigationInterface, didFailWithError error: Error) {
Logger.logErrorMessage("Navigation error: \(error)")
self.stopNavigation()
self.view?.stopNavigation(status: .error(error))
}

func navigationManager(_ navigationManager: SITNavigationInterface, didUpdate progress: SITNavigationProgress, on route: SITRoute) {
Expand All @@ -460,8 +435,7 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate

func navigationManager(_ navigationManager: SITNavigationInterface, destinationReachedOn route: SITRoute) {
Logger.logDebugMessage("Destination reached")
view?.showAlertMessage(title: "Destination Reached", message: "You've arrived to your destination", alertType: .otherAlert)
view?.stopNavigation()
self.view?.stopNavigation(status: .destinationReached)
}

func navigationManager(_ navigationManager: SITNavigationInterface, userOutsideRoute route: SITRoute) {
Expand All @@ -470,8 +444,7 @@ class PositioningPresenter: NSObject, SITLocationDelegate, SITDirectionsDelegate
if isUserIndoor(){
showAlertIfNeeded(type: .outsideRoute, title: self.outsideRouteAlertTitle, message: "The user is not currently detected on the route. Please go back to resume navigation.")
}else{
view?.stopNavigation()
alertUserOfInvalidDirectionsRequest(error: .SITOutdorOriginError)
view?.stopNavigation(status: .error(NavigationError.outsideBuilding))
}
}

Expand Down

0 comments on commit 91c245d

Please sign in to comment.