Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waze doesn't load navigation from Swift

I integrated Waze into my Swift app, but when I click on the button, Waze opens but nothing happens with the navigation. I juste see the app and that's all, instead of launching the navigation.

Here is the code:

@IBAction func openWazeAction(_ sender: Any) {
    // open waze
    if UIApplication.shared.canOpenURL(URL(string: "waze://")!) {
        let urlStr = String(format: "waze://ul?ll=%f,%f&navigate=yes", (selectedBorne?.location?.x)!, (selectedBorne?.location?.y)!)

        print(urlStr)

        UIApplication.shared.open(URL(string: urlStr)!)
    } else {
        UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
    }
}

The print(urlStr) returns the right URL: waze://ul?ll=48.792914,2.366290&navigate=yes, but nothing happens in the Waze app.

(I put the LSApplicationQueriesSchemes in the Info.plist file.)

What is wrong here?

like image 337
cusmar Avatar asked Feb 07 '18 10:02

cusmar


People also ask

Why can't Waze find GPS?

I see an error message in Waze If you encounter an error about Waze and your phone's location settings, do the following: Tap My Waze, then Settings. Tap Privacy, then Location Services. Turn off Location Services.

Why is Waze not connecting?

To fix the Waze app no network connection problems, you can try these options: Restart the phone. Clear the Waze cache. Delete the app and install it again.

Why is my Waze not opening?

Waze application may not work due to the wrong configuration of the power options (like battery saver, battery optimization, power-saving location setting, etc.). Moreover, corrupt cache partition or corrupt installation of Android Auto may also cause the error under discussion.


1 Answers

I fixed the problem. The Waze documentation gives wrong information because their iOS example doesn't open the Waze app as it should be. It opens Safari on mobile and then we need to click on a link to open Waze.

The correct link is:

waze://?ll={latitude},{longitude}&navigate=yes

I needed to remove ul in the URL.


Swift

func navigateTo(latitude: Double, longitude: Double) {
    if UIApplication.shared.canOpenURL(URL(string: "waze://")!) {
        // Waze is installed. Launch Waze and start navigation
        let urlStr = String(format: "waze://?ll=%f,%f&navigate=yes", latitude, longitude)
        UIApplication.shared.open(URL(string: urlStr)!)
    } else {
        // Waze is not installed. Launch AppStore to install Waze app
        UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
    }
}

Objective-C

(void) navigateToLatitude:(double)latitude longitude:(double)longitude
{
  if ([[UIApplication sharedApplication]
    canOpenURL:[NSURL URLWithString:@"waze://"]]) {
      // Waze is installed. Launch Waze and start navigation
      NSString *urlStr =
        [NSString stringWithFormat:@"waze://?ll=%f,%f&navigate=yes",
        latitude, longitude];
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
  } else {
    // Waze is not installed. Launch AppStore to install Waze app
    [[UIApplication sharedApplication] openURL:[NSURL
      URLWithString:@"http://itunes.apple.com/us/app/id323229106"]];
  }
}
like image 172
cusmar Avatar answered Oct 26 '22 18:10

cusmar