Установите язык навигации в Mapbox Navigation с помощью React Native & Swift - PullRequest
0 голосов
/ 29 марта 2020

Я пытаюсь создать компонент навигации Mapbox с помощью React Native. Я запустил его с кодом ниже. Мой следующий шаг - установить правильный голосовой язык для навигации, который будет исходить из реагирующей родной локализации. У меня 0 опыта работы со Swift и я не нашел хороших решений в документации. Итак, мой вопрос, каков наилучший способ реализовать его через собственный компонент React? Вся помощь приветствуется. Спасибо

Реагировать на собственный компонент

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 File

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)
    }
  }
}
...