Ran*_*eek 2 arrays coordinates ios swift waze
我正在尝试Waze使用自己的API在我的应用程序中实现导航:这里.
我想设置in custom coordinates,array
然后在这段代码中使用它们:
func navigate(toLatitude latitude: Double , longitude: Double) {
if UIApplication.shared.canOpenURL(URL(string: "waze://")!) {
// Waze is installed. Launch Waze and start navigation
let urlStr: String = "waze://?ll=\(latitude),\(longitude)&navigate=yes"
UIApplication.shared.openURL(URL(string: urlStr)!)
}
else {
// Waze is not installed. Launch AppStore to install Waze app
UIApplication.shared.openURL(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
}
}
Run Code Online (Sandbox Code Playgroud)
我已尝试设置不同类型的阵列,但没有成功使其工作.所以,如果你可以帮我设置自定义数组,保持纬度和经度可以正常使用代码,这将是很棒的
你的帮助会非常有帮助,
先感谢您.
Wazeapp仅支持目的地latitude和longitude.
waze://?ll=<lat>,<lon>&navigate=yes
CLLocationCordiates将期望两个参数latitude和longitude,这是CLLocationDegrees类型.CLLocationDegrees只不过是Double价值.
let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
Run Code Online (Sandbox Code Playgroud)
如果你有双重值,则不需要构造为CLLocationCoordinate2D.你可以使用你在问题中提到的相同的function- >navigate()
将值传递给以下函数以打开Waze应用程序.
func openWaze(location : CLLocationCoordinate2D) {
if UIApplication.shared.canOpenURL(URL(string: "waze://")!) {
// Waze is installed. Launch Waze and start navigation
let urlStr: String = "waze://?ll=\(location.latitude),\(location.longitude)&navigate=yes"
UIApplication.shared.openURL(URL(string: urlStr)!)
}
else {
// Waze is not installed. Launch AppStore to install Waze app
UIApplication.shared.openURL(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
}
}
Run Code Online (Sandbox Code Playgroud)
使用 iOS SDK 9.0 及更高版本进行编译时,您必须使用以下内容更新应用程序的属性列表文件以包含 Waze:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
</array>Run Code Online (Sandbox Code Playgroud)