2017-07-09 51 views
0

我试图在我的应用中使用Waze实现导航,使用他们自己的API:here将自定义坐标设置为函数,Waze集成

我都希望使用在array 设置custom coordinates设置,然后配合他们在这个代码:

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

我已经尝试设置了不同类型的数组,但没有成功,使这行得通 。所以,如果你可以帮助我组自定义列保持纬度和经度,将与代码正常工作,这将是真棒

你的帮助会非常有帮助的,

预先感谢您。

+0

你是什么意思的自定义坐标? – Subramanian

+0

就像我会创建自己的坐标数组,我控制他们的度数,我会设置func导航到该坐标数组。你现在明白了? @Subramanian – RandomGeek

+0

但是他们的apis不支持坐标数组right .. – Subramanian

回答

2

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

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

CLLocationCordiates将期望两个参数latitudelongitude,这是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")!) 
    } 
} 
+0

嘿由于某种原因,行动不被称为....这是奇怪的...检查此:https:// stackoverflow。com/questions/44999453/alertviewcontroller-button-function-not-working – RandomGeek

+0

谢谢!与您的帮助和其他我得到这个东西正常工作....非常感谢人:) – RandomGeek

0

要为持有土地增值税和长期创建自定义数组:

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]]; 

替代纬度长值。