4

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

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

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

您的帮助将非常有帮助,

先感谢您。

4

3 回答 3

9

Waze应用程序仅支持目的地latitudelongitude

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

CLLocationCordiates将期望两个参数latitudelongitude,这是CLLocationDegrees类型。CLLocationDegrees无非是Double价值。

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

如果您有 double 值,则无需构造 as 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")!)
    }
}
于 2017-07-09T17:30:09.250 回答
5

使用 iOS SDK 9.0 及更高版本进行编译时,您必须使用以下内容更新应用程序的属性列表文件以包含 Waze:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>waze</string>
</array>

于 2019-05-27T08:07:04.103 回答
0

要创建用于保存 lat 和 long 的自定义数组:

NSMutableArray *latLongArray = [[NSMutableArray alloc]init];
[latLongArray addObject :[NSDictionary dictionaryWithObjectsAndKeys:lat,@"latitude",long,@"longitude",nil]];
[latLongArray addObject :[NSDictionary dictionaryWithObjectsAndKeys:lat,@"latitude",long,@"longitude",nil]];
[latLongArray addObject :[NSDictionary dictionaryWithObjectsAndKeys:lat,@"latitude",long,@"longitude",nil]];

替换 lat long 值。

于 2017-07-09T16:33:34.220 回答