Mapbox中没有语音命令转向方向视图

时间:2019-07-17 02:18:41

标签: ios swift mapbox directions

所以我已经使用两种不同的样式在Mapbox上制作了地图。总而言之,一切正常,直到应该发出下一声等的语音命令为止。

我曾经尝试过使用mapboxVoiceController,因此我不知道还有什么可以尝试的。

     var voiceController: RouteVoiceController!


     func calculateRoute(from originCoor: CLLocationCoordinate2D,
                         to destinationCoor: CLLocationCoordinate2D,
                         completion: @escaping (Route?, Error?) -> Void) {

        // Coordinate accuracy is the maximum distance away from the waypoint that the route may still be considered viable, measured in meters. Negative values indicate that a indefinite number of meters away from the route and still be considered viable.
        let origin = Waypoint(coordinate: originCoor, coordinateAccuracy: -1, name: "Start")
        let destination = Waypoint(coordinate: destinationCoor, coordinateAccuracy: -1, name: "Finish")

        // Specify that the route is intended for automobiles avoiding traffic

        let options = RouteOptions(waypoints: [origin, destination], profileIdentifier: .automobileAvoidingTraffic)
        options.routeShapeResolution = .full
        options.includesSteps = true
        options.includesVisualInstructions = true
        options.includesSpokenInstructions = true
        options.includesExitRoundaboutManeuver = true

        _ = Directions.shared.calculate(options) { [unowned self] (waypoints, routes, error) in
            guard let route = routes?.first else { return }
            let defaults = UserDefaults.standard
            let mapPref = defaults.object(forKey: "mapPref") as! String
            let navigationService = MapboxNavigationService(route: route)
            self.voiceController = RouteVoiceController(navigationService: navigationService)


            //loads map based on user Pref

            if mapPref == "0" {
                let newDayStyle = NavigationOptions(styles: [mapDayStyle()], navigationService: navigationService, voiceController: self.voiceController)
                let viewController = NavigationViewController(for: route, options: newDayStyle)
                self.present(viewController, animated: true, completion: nil)
            } else {
                let newNightStyle = NavigationOptions(styles: [mapNightStyle()], navigationService: navigationService, voiceController: self.voiceController)
                let viewController = NavigationViewController(for: route, options: newNightStyle)
                self.present(viewController, animated: true, completion: nil)
            }

        }

     }

和我的两个不同的地图类:

     // DayMap Mode

     class mapDayStyle : DayStyle {

        required init() {
            super.init()
            mapStyleURL = URL(string: "mapbox://styles/tristanmellett/cjxfrpz7x04881cmj8er9avsf")!
            styleType = .day
        }

        override func apply() {
            super.apply()
            BottomBannerView.appearance().backgroundColor = .white
        }
     }

     //Night Map Mode
     class mapNightStyle : NightStyle {

        required init() {
            super.init()
            mapStyleURL = URL(string: "mapbox://styles/tristanmellett/cjxtzfdrb8ttb1ckc9dpgf18a")!
            styleType = .night

        }

        override func apply() {
            super.apply()
            BottomBannerView.appearance().backgroundColor = .darkGray
            TopBannerView.appearance().backgroundColor = .darkGray
        }
     }

我希望语音命令开始工作。

0 个答案:

没有答案