【问题标题】:Sygic issue in showing the map显示地图的 Sygic 问题
【发布时间】:2018-08-19 16:12:35
【问题描述】:

我在使用 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 No SSO session,无法发送 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!)
        }

请帮忙

【问题讨论】:

    标签: ios swift sygic sygic-mobile-sdk


    【解决方案1】:

    首先你有有效的密钥和秘密吗?如果没有,您可以在这里申请:https://www.sygic.com/business/request-sygic-mobile-sdk-api-key?product=mobileSdk 我知道您在示例中使用的不是真实的,但至少错误似乎您使用的错误无效。

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

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

    【讨论】:

    • 谢谢,我得到了一个有效的密钥,但我仍然得到一个空地图。我使用了官方文档,但是没有用。老实说,我不明白你关于 sdk 初始化的想法
    • 我对代码进行了一些更改,但仍然得到空地图
    • 嗨@anonym 我进行了更改,现在在初始化 sdk 后加载了地图视图,但我仍然得到一个空地图。请给个主意???
    • @WalidSassi 你得到的是黑色地图还是灰色地图?后者表示地图视图加载正确但没有下载地图或在线地图下载失败,如果是黑色则表示其他问题...
    • 是的,我得到了灰色地图类型,当我缩小时,我得到了整个地球,但没有瓷砖。我认为是 arcgis sdk 中的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多