我正在尝试使用 React Native 创建一个 Mapbox 导航组件。所以我的问题是通过 React Native 组件实现它的最佳方式是什么?感谢所有帮助。谢谢
注册护士组件
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)
);
迅捷类
import Foundation
import UIKit
import MapboxCoreNavigation
import MapboxNavigation
import MapboxDirections
import 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)
}
}
}