首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将自定义坐标设置为函数,Waze集成

将自定义坐标设置为函数,Waze集成
EN

Stack Overflow用户
提问于 2017-07-09 15:13:35
回答 3查看 4.9K关注 0票数 4

我试图在我的应用程序中使用Waze实现导航,使用他们自己的API:这里

我想在custom coordinates中设置在array中设置的内容,然后将它们放入代码:中。

代码语言:javascript
复制
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")!)
                }
            }

我尝试过设置不同类型的数组,但没有成功地使其工作。因此,如果您可以帮助我设置包含纬度和经度的自定义数组,以便与代码正确地工作,那将是非常棒的。

你的帮助会很有帮助,

提前谢谢你。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-07-09 17:30:09

Waze应用程序只支持目标latitudelongitude

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

CLLocationCordiates需要两个参数latitudelongitude,这两个参数是CLLocationDegrees类型。CLLocationDegrees不过是Double值。

代码语言:javascript
复制
let location =  CLLocationCoordinate2D(latitude: latitude, longitude: longitude)

如果您有双值,那么就不需要构造为CLLocationCoordinate2D。您可以使用您在问题中提到的function -> navigate()

将值传递给下面的函数以打开Waze应用程序。

代码语言:javascript
复制
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")!)
    }
}
票数 9
EN

Stack Overflow用户

发布于 2019-05-27 08:07:04

在使用iOS SDK9.0及更高版本进行编译时,必须使用以下内容更新应用程序的属性列表文件,以包括Waze:

代码语言:javascript
复制
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>waze</string>
</array>

票数 5
EN

Stack Overflow用户

发布于 2017-07-09 16:33:34

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

代码语言:javascript
复制
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]];

代替长值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44997905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档