2017-07-09 53 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]]; 

替代緯度長值。