我将Waze集成到了我的Swift应用程序中,但是当我单击按钮时,Waze打开了,但是导航没有任何反应。我只是看到该应用程序,仅此而已,而不是启动导航。
这是代码:
@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")!)
}
}
在print(urlStr)
返回正确的网址:waze://ul?ll=48.792914,2.366290&navigate=yes
,但没有发生在Waze的应用程序。
(我将LSApplicationQueriesSchemes放在Info.plist文件中。)
这是怎么了
我解决了这个问题。在Waze的文档提供了错误的信息,因为他们的iOS例如不开的Waze应用程序,因为它应该是。它会在移动设备上打开Safari,然后我们需要单击链接以打开Waze。
正确的链接是:
waze://?ll={latitude},{longitude}&navigate=yes
我需要删除ul
网址。
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")!)
}
}
(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"]];
}
}
太好了,但是如果我想按搜索词而不是长/短导航,该怎么办?
您应该对搜索词进行编码(如here),然后像这样在您的URL中传递它:
waze://?q=
搜索词。尝试此操作
"waze://?q=19+Hatzfira+st,+Jerusalem,+Israel"
,将打开位智但不导航。您应该使用GeoCode将搜索词转换为纬度和经度
您可以尝试这样做:
query = 'gas station Israel'
waze://?q=query
它对我有用,如果用户没有在设备上醒来,则可以在浏览器中打开,如下所示:https://waze.com/ul?q=${query}