swiftxcode8ios10yandex-mapsyandex-api

How can I launch yandex maps application from external app in swift?


I have latitude and longitude information for source and destination, I want to send this information to yandex maps and yandex maps should show directions. How can I do this in Swift 3?


Solution

  • You should use Yandex's URL-Scheme (yandexmaps://build_route_on_map/?params)

    Example in swift 3:

    let url = URL(string: "yandexmaps://build_route_on_map/?lat_from=XXXXX&lon_from=XXXXX&lat_to=XXXXX&lon_to=XXXXX")!
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.openURL(url)
    }
    

    Remember to check if the app can be opened.

    if UIApplication.shared.canOpenURL(url) {
        // Open the URL here
    }