Waze doesn't load navigation from Swift
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"]];
}
}