显示地图时出现的Sygic问题

时间:2018-08-19 16:12:35

标签: ios swift sygic sygic-mobile-sdk

我对Sygic地图框架有疑问,我尝试使用此代码显示地图 在AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        SYContext.initWithAppKey("mhives.sdk.trial", appSecret: "2nxScQJ0s/J6FsYJ67dlQ+MZLjLzOKc0s96l0t4YyLv2IH8b31b5vWgkzbfgJZ8FYEKQtxpLFGlwyfqEQ64MSQ==") { (initResult) in
        if (initResult == .success) {
            self.window = UIWindow(frame: UIScreen.main.bounds)
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let initialViewController:ViewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
            // Set that ViewController as the rootViewController
            self.window?.rootViewController = initialViewController
            self.window?.makeKeyAndVisible()
            initialViewController.sdkDidStart()

        } else {
            print("KO")
        }
    }
        return true
    }

ViewController.swift

class ViewController: UIViewController,SYMapViewDelegate,SYRoutingDelegate {
let mapView = SYMapView()
let routing = SYRouting()
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func mapView(_ mapView: SYMapView, didFinishInitialization success: Bool) {
        let tiltFor2D: SYAngle = 0
        mapView.tilt = tiltFor2D
        self.mapView.zoom = 10
        self.mapView.rotation = 180
        self.mapView.geoCenter = SYGeoCoordinate(latitude: 48.147, longitude: 17.101878)!
        self.mapView.frame = self.view.bounds
        view.addSubview(self.mapView)

    }

    func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate: SYGeoCoordinate) {
        // Create an instance of SYRouting


        // Make self a delegate for SYRouting to receive and handle SYRoutingDelegate responses

        // Create SYWaypoint from coordinate. Set correct SYWaypointType for start and finish.
        let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start, name: nil)
        let endWaypoint = SYWaypoint(position: toCoordinate, type: .end, name: nil)

        // Optionally: create an instance of SYRoutingOptions for configuring computing of a route
        let routingOptions = SYRoutingOptions()
        routingOptions.transportMode = .pedestrian // For other options see SYTransportMode
        routingOptions.routingType = .economic// For other options see SYRoutingType

        // Start computing route
        self.routing.computeRoute(startWaypoint, to: endWaypoint, via: nil, with: routingOptions)
    }

    func routing(_ routing: SYRouting, computingFailedWithError error: SYRoutingError) {
        print(error.rawValue)
    }

    func routing(_ routing: SYRouting, didComputePrimaryRoute route: SYRoute?) {
        SYNavigation.shared().start(with: route)

        // You might want to put it also on the map

        let mapRoute = SYMapRoute(route: route!, type: .primary)
        mapView.add(mapRoute)
    }

现在,我尝试仅显示Sygic映射,但没有得到,我在调试器中收到此消息“ Sygic:W 18/08/19 17:04:51没有SSO会话,无法发送http请求!“

func sdkDidStart(){

           mapView.delegate = self
            routing.delegate = self

            self.mapView.frame = self.view.bounds
            self.view.addSubview(self.mapView)
            let start = SYGeoCoordinate(latitude: 37.276758, longitude: 9.864160900000002)
            let end = SYGeoCoordinate(latitude: 37.25408, longitude:  9.906733)
            //computeRoute(from: start!, to: end!)
        }

请帮助

1 个答案:

答案 0 :(得分:4)

首先,您有有效的密钥和机密吗?如果没有,您可以在这里请求:https://www.sygic.com/business/request-sygic-mobile-sdk-api-key?product=mobileSdk 我了解您在这里没有使用真正的示例,但是至少该错误似乎像您正在使用的那个无效。

另一件事是,什么时候初始化SYMapView?例如,如果您使用情节提要加载ViewController作为初始视图控制器,则它将在完全加载SDK之前尝试加载地图视图实例及其所有基础组件。注意,只有在成功初始化SDK之后,您才可以使用它。

因此,请检查您的API密钥,并尝试在SYContext.initWithAppKey()完成处理程序中初始化该视图控制器。