首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >地图框导航:“Route”类型的值没有成员“member”

地图框导航:“Route”类型的值没有成员“member”
EN

Stack Overflow用户
提问于 2020-01-27 09:01:08
回答 2查看 511关注 0票数 0

类型为“Route”的值没有成员“coordinates”

在学习简单的youtube教程时遇到了这个错误。试着画一条路线。有人知道我为什么会收到这个错误吗?是pods的问题吗?

这些都是安装好的。谢谢!

代码语言:javascript
复制
    pod 'Mapbox-iOS-SDK', '~> 5.6'
      pod 'MapboxCoreNavigation', :git => 'https://github.com/mapbox/mapbox-navigation-ios.git', :tag => 'v1.0.0-alpha.1'
      pod 'MapboxNavigation', :git => 'https://github.com/mapbox/mapbox-navigation-ios.git', :tag => 'v1.0.0-alpha.1'
EN

回答 2

Stack Overflow用户

发布于 2020-01-27 12:50:45

所以我设法找到了示例应用程序和错误。

以下是示例应用程序中的代码,它给出的错误为

’类型的coordinates值没有成员'coordinates‘@routes?.first?.coordinates

代码语言:javascript
复制
Directions.shared.calculate(routeOptions) { (waypoints, routes, error) in
        guard let routeCoordinates = routes?.first?.coordinates, error == nil else {
            print(error!.localizedDescription)
            return
        }

        //
        // ❗️IMPORTANT❗️
        // Use `Directions.calculateRoutes(matching:completionHandler:)` for navigating on a map matching response.
        //
        let matchOptions = NavigationMatchOptions(coordinates: routeCoordinates)

        // By default, each waypoint separates two legs, so the user stops at each waypoint.
        // We want the user to navigate from the first coordinate to the last coordinate without any stops in between.
        // You can specify more intermediate waypoints here if you’d like.
        for waypoint in matchOptions.waypoints.dropFirst().dropLast() {
            waypoint.separatesLegs = false
        }

        Directions.shared.calculateRoutes(matching: matchOptions) { (waypoints, routes, error) in
            guard let route = routes?.first, error == nil else { return }

            // Set the route
            self.navigationViewController?.route = route
        }
    }

它必须按如下方式重写。

代码语言:javascript
复制
        Directions.shared.calculate(routeOptions) { (waypoints, routes, error) in
        guard let firstRoute = routes?.first, let waypoints = waypoints, error == nil else {
            print(error!.localizedDescription)
            return
        }

        //
        // ❗️IMPORTANT❗️
        // Use `Directions.calculateRoutes(matching:completionHandler:)` for navigating on a map matching response.
        //

        let matchOptions = NavigationMatchOptions(waypoints: waypoints)

        // By default, each waypoint separates two legs, so the user stops at each waypoint.
        // We want the user to navigate from the first coordinate to the last coordinate without any stops in between.
        // You can specify more intermediate waypoints here if you’d like.
        for waypoint in matchOptions.waypoints.dropFirst().dropLast() {
            waypoint.separatesLegs = false
        }

        Directions.shared.calculateRoutes(matching: matchOptions) { (waypoints, routes, error) in
            guard let route = routes?.first, error == nil else { return }

            // Set the route
            self.navigationViewController?.route = route
        }
    }

请检查这是否解决了您的问题

票数 2
EN

Stack Overflow用户

发布于 2020-01-27 13:02:21

安装在pod下方

代码语言:javascript
复制
pod 'Mapbox-iOS-SDK', '~> 5.2'  
pod 'MapboxNavigation', '~> 0.38.0'

然后写下下面的代码,它对我很有效

代码语言:javascript
复制
if(CLLocationManager.locationServicesEnabled()){

self.CurrentLat = self.locationManager.location?.coordinate.latitude

self.CurrentLong = self.locationManager.location?.coordinate.longitude

let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 
self.CurrentLat, longitude: self.CurrentLong), name: "Start Location")

let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: yourDestinationLat, 
longitude:  yourDestinationLong), name: yourDestinationName)
// Set options
let options = NavigationRouteOptions(waypoints: [origin, destination])

// Request a route using MapboxDirections.swift
Directions.shared.calculate(options) { (waypoints, routes, error) in

guard let route = routes?.first else {
SVProgressHUD.showError(withStatus: "Unable to create a route. Please try 
again.")
   return
}

let viewController = NavigationViewController(for: route)
viewController.delegate = self
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true, completion: nil)
SVProgressHUD.dismiss()
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59924197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档