Im trying to create a Mapbox navigation component with React Native. So my question is whats the best way to implement it via the React Native Component? All help is appreciated. Thanks
RN Component
var navDemo = NativeModules.NavDemo; navDemo.renderNaviDemo( (originLat = this.props.currentLocation.coords.latitude), (originLon = this.props.currentLocation.coords.longitude), (originName = "Start"), (destinationLat = this.state.manoeuvreDetails.geometry .coordinates[1]), (destinationLon = this.state.manoeuvreDetails.geometry .coordinates[0]), (destinationName = this.state.manoeuvreDetails.name) );
Swift Class
import Foundationimport UIKitimport MapboxCoreNavigationimport MapboxNavigationimport MapboxDirectionsimport Mapbox@objc(NavDemo)class NavDemo: NSObject { @objc func renderNaviDemo(_ originLat: NSNumber, oriLon originLon: NSNumber, oriName originName: NSString, destLat destinationLat: NSNumber, destLon destinationLon: NSNumber, destName destinationName: NSString) { let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: CLLocationDegrees(truncating: originLat), longitude: CLLocationDegrees(truncating: originLon)), name: originName as String) let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: CLLocationDegrees(truncating: destinationLat), longitude: CLLocationDegrees(truncating: destinationLon)), name: destinationName as String) let options = NavigationRouteOptions(waypoints: [origin, destination]) Directions.shared.calculate(options) { (waypoints, routes, error) in guard let route = routes?.first else { return } let navigationService = MapboxNavigationService(route: route, simulating: .never) let navigationOptions = NavigationOptions(navigationService: navigationService) let viewController = NavigationViewController(for: route, options: navigationOptions) let appDelegate = UIApplication.shared.delegate appDelegate!.window!!.rootViewController!.present(viewController, animated: true, completion: nil) } }}