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 location manager for free drive #2410

Merged
merged 19 commits into from
Aug 18, 2020
Merged

Add location manager for free drive #2410

merged 19 commits into from
Aug 18, 2020

Conversation

IodaMikeMapbox
Copy link
Contributor

@IodaMikeMapbox IodaMikeMapbox commented Jun 22, 2020

The pr adds implementation of NavigationLocationManager which processes raw gps values with the Navigator in order to map them to the road graph.

Fixes #1627, fixes #2456.

/cc @mapbox/navigation-ios

@IodaMikeMapbox IodaMikeMapbox requested a review from 1ec5 June 22, 2020 16:14
@IodaMikeMapbox IodaMikeMapbox self-assigned this Jun 22, 2020
@IodaMikeMapbox IodaMikeMapbox force-pushed the ima-free-drive branch 2 times, most recently from 7600900 to a7fc221 Compare July 16, 2020 11:31
@zugaldia zugaldia added the release blocker Needs to be resolved before the release. label Aug 4, 2020
@1ec5 1ec5 changed the base branch from master to release-v1.0-pre-registry August 4, 2020 23:15
@1ec5

This comment has been minimized.

MapboxCoreNavigation/FreeDriveLocationManager.swift Outdated Show resolved Hide resolved
MapboxCoreNavigation/FreeDriveLocationManager.swift Outdated Show resolved Hide resolved
MapboxCoreNavigation/FreeDriveLocationManager.swift Outdated Show resolved Hide resolved
MapboxNavigation/FreeDriveDebugger.swift Outdated Show resolved Hide resolved
@1ec5 1ec5 changed the base branch from release-v1.0-pre-registry to master August 5, 2020 20:46
@IodaMikeMapbox
Copy link
Contributor Author

The pr uses @dersim-davaod's commit from temp-route-tiles-logic branch, as I see the work from that branch was utilised in #2533

@dersim-davaod
Copy link
Contributor

@IodaMikeMapbox thanks for notifying. it will be slightly changed in #2533, but that's fine. If the current changes will be merged first, that's also fine, I'll handle a proper rebase.

@1ec5 1ec5 added this to the v1.0.0 milestone Aug 11, 2020
MapboxCoreNavigation/MBXPeerWrapper.h Show resolved Hide resolved
MapboxCoreNavigation/RouteTiles.swift Outdated Show resolved Hide resolved
MapboxCoreNavigation/URLSession.swift Outdated Show resolved Hide resolved
MapboxCoreNavigation/FreeDriveLocationManager.swift Outdated Show resolved Hide resolved
YodaMike and others added 14 commits August 17, 2020 18:25
Decoupled tile directory creation and navigator configuration from location manager initialization. Client code needs to explicitly start location updates after creating the location manager, just like with an ordinary CLLocationManager. Starting location updates causes a completion handler to be called. The completion handler accepts any error that occurs during tile directory creation, so that the application can catch and handle the error instead of crashing.
Inverted FreeDriveLocationManager to be a delegate of a CLLocationManager that is responsible for talking to the navigator in much the same way that RouteController does. Removed FreeDriveDebugInfoListener and FreeDriveLocationManager.ProxyDelegate in favor of FreeDriveLocationManagerDelegate.

Moved debugging utilities from MapboxNavigation to the example application targets and out of the project root. Removed remaining vestiges of MapboxNavigationNative from the MapboxNavigation public API.
…ive debugger

Send a notification alongside the delegate method whenever the free drive location manager updates.

Draw the raw and idealized user location paths using mutable polyline annotations instead of runtime styling. Polyline annotations are easier and more performant to update synchronously. Deleted the table view for matches.
Update the title bar to display the current road name.
There’s no good way to mock a route tile request at the moment, so disable the test instead of requiring network access.
The distinction between the MapboxCoreNavigation and MapboxNavigation free driving classes is easier to make if we call one a location data source, borrowing from RouteDataSource terminology, and the other a location manager, for consistency with MGLLocationManager. This naming convention also avoids the awkwardness of beginning class names with a noun phrase that could easily be misread as a verb phrase.

Added a changelog entry.

trackLocations(mapView: mapView)
mapView.showsUserLocation = true
mapView.userTrackingMode = .followWithHeading
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map view isn’t showing the heading indicator for some reason. I think it has to do with the location manager only delivering location updates and not heading updates. In any case, I don’t think we want the map view to rotate with the user’s heading or course, because frequent rotation makes the map much less useful for choosing a destination.

Comment on lines +43 to +44
// Assumption: MapboxNavigation.framework includes NavigationViewController and exposes it to the Objective-C runtime as MapboxNavigation.NavigationViewController.
guard let NavigationViewController = NSClassFromString("MapboxNavigation.NavigationViewController") else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’ve been making this assumption since #2221. This change just moves it somewhere more accessible to non-events-related code.

MapboxCoreNavigation/RouteTiles.swift Outdated Show resolved Hide resolved

The user agent string for any HTTP requests performed directly within MapboxCoreNavigation or MapboxNavigation.
*/
public static let userAgent: String = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason we use custom User-Agent? (NSURLSessionsets User-Agent by default). I can also see that Directions.swift uses pretty similar approach when creating userAgent so might make sense to have some common way of creating it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should always customize the user agent string to provide more context in the server logs than the application and Core Foundation versions, which is what URLSession provides by default. This particular user agent string is specific to requests made by MapboxCoreNavigation or MapboxNavigation.

locationManager.updateLocation(CLLocation(latitude: 47.208674, longitude: 9.524650))
}

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(25)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to review this test in future since it's time consuming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, in fact, I disabled this test because it requires network access and a valid Mapbox access token to function at all. We’ll figure out a better integration test as tail work. I just rewrote history in this PR to undo the change that deleted the offline routing tests; I think we could possibly leverage that test’s test fixture to avoid reinventing the wheel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MapboxCoreNavigationTests/TileRoutingVersionTests.swift Outdated Show resolved Hide resolved
MapboxCoreNavigation/RouteTiles.swift Outdated Show resolved Hide resolved
MapboxCoreNavigationTests/TileRoutingVersionTests.swift Outdated Show resolved Hide resolved
self.directions = directions

let settingsProfile = SettingsProfile(application: ProfileApplication.kMobile, platform: ProfilePlatform.KIOS)
self.navigator = Navigator(profile: settingsProfile, config: NavigatorConfig() , customConfig: "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that @SiarheiFedartsou was mentioning that it can be beneficial to use one global MBNavigator and feed it with data whenever it's available. Since we now have 4 (?) places where MBNavigator is created it might make sense to consider one global instance approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, for better or worse, the navigator is intended to be used as something of a singleton if I remember correctly.

#2509 will remove two of these initializations, leaving just the ones in RouteController and PassiveLocationDataSource, so I didn’t bother to centralize the logic just yet.

The long-term vision is indeed to unify PassiveLocationDataSource and RouteController, so that the latter is just a special case of setting a route on the former and keeping track of route progress. For now, we would probably recommend that the developer stop location updates on PassiveLocationDataSource when beginning turn-by-turn navigation with RouteController. This happens to be the case in the example application, because it demonstrates temporarily taking the main map view out of the view hierarchy as a performance optimization.

Reuse the better-tested, more strongly typed implementation of route tiles API integration in MapboxDirections. Removed the user default and property for the current version, which appears to be unused.
@1ec5
Copy link
Contributor

1ec5 commented Aug 18, 2020

Based on the feedback in #2410 (review), I removed the RouteTilesVersion implementation outright in favor of the preexisting routing tiles API support in MapboxDirections, which is better tested and slightly more strongly typed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request. release blocker Needs to be resolved before the release. topic: location
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indicate current road name during free-driving Make route snapping logic available for external developers?
6 participants