-canOpenURL: failed for URL: "comgooglemaps://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

Viewed 1555

I am using google maps. I have latitude and longitude given. I need to show location on maps using coordinates. But I get error as :

-canOpenURL: failed for URL: "comgooglemaps://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)" And it prints the else part as: "Can't use comgooglemaps://"

In info.plist I have added : 1. LSApplicationQueriesSchemes Item 0 String googlechromes Item 1 String comgooglemaps

  1. Privacy - Location When In Use Usage Description

My code is given :

import UIKit
import MapKit

class MapViewController: UIViewController, MKMapViewDelegate {  

  var data7: String?
  var data8: String?

  override func viewDidLoad() {
     super.viewDidLoad()

     getAddress()
    }

  func getAddress() {

    if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
      UIApplication.shared.openURL(URL(string:"comgooglemaps://?saddr=&daddr=\(data7),\(data8)&directionsmode=driving")!)
    }
    else {

      print("Can't use comgooglemaps://");
    }
}
1 Answers

Run your app on a physical device (NOT Simulator) that does have the google maps app and it should launch correctly using your code.

Related