我试图在我的应用程序中使用Waze实现导航,使用他们自己的API:这里。
我想在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")!)
}
}我尝试过设置不同类型的数组,但没有成功地使其工作。因此,如果您可以帮助我设置包含纬度和经度的自定义数组,以便与代码正确地工作,那将是非常棒的。
你的帮助会很有帮助,
提前谢谢你。
发布于 2017-07-09 17:30:09
Waze应用程序只支持目标latitude和longitude。
waze://?ll=<lat>,<lon>&navigate=yes
CLLocationCordiates需要两个参数latitude和longitude,这两个参数是CLLocationDegrees类型。CLLocationDegrees不过是Double值。
let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)如果您有双值,那么就不需要构造为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")!)
}
}发布于 2019-05-27 08:07:04
在使用iOS SDK9.0及更高版本进行编译时,必须使用以下内容更新应用程序的属性列表文件,以包括Waze:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
</array>
发布于 2017-07-09 16:33:34
若要创建用于保存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]];代替长值。
https://stackoverflow.com/questions/44997905
复制相似问题