gpt4 book ai didi

ios - 将自定义坐标设置为函数,Waze Integration

转载 作者:可可西里 更新时间:2023-10-31 23:57:35 31 4
gpt4 key购买 nike

我正在尝试在我的应用程序中使用 Waze 实现导航,使用他们自己的 API:here .

我想在数组中设置自定义坐标然后将它们放入此代码中:

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")!)
}
}

我试过设置不同类型的阵列,但没能成功。因此,如果您能帮助我设置自定义数组,其中包含可以与代码一起正常工作的纬度和经度,那就太棒了

你的帮助会很有帮助,

提前谢谢你。

最佳答案

Waze应用仅支持目的地 latitudelongitude .

waze://?ll=<lat>,<lon>&navigate=yes

CLLocationCordiates将需要两个参数 latitudelongitude ,即 CLLocationDegrees类型。 CLLocationDegrees只不过是 Double值(value)。

let location =  CLLocationCoordinate2D(latitude: latitude, longitude: longitude)

如果您有 double 值,则无需构建为 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")!)
}
}

关于ios - 将自定义坐标设置为函数,Waze Integration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44997905/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com