2016-08-02 71 views
0

我使用Indoo.rs ios sdk由swift構建一個小應用程序來顯示我的地圖,問題是我不知道寫一個代碼來設置2點之間的路線在地圖上,我碰到的文件,但沒有結果出來...這裏是我的代碼:使用Indoo.rs設置路線在地圖上使用Indoo.rs ios sdk

的文檔是在這裏:https://indoors.readme.io/docs/routing-1

如有與我的任何想法份額。 感謝

import UIKit 

import CoreLocation 

class ViewController: UIViewController , RoutingDelegate ,IndoorsServiceDelegate, ISIndoorsSurfaceViewControllerDelegate ,IndoorsSurfaceViewDelegate { 

    @IBOutlet var SetRouteButton: UIButton! 

    var _currentBuilding: IDSBuilding? 
    var dot : ISIndoorsSurface? 
    var _indoorsSurfaceViewController: ISIndoorsSurfaceViewController? 

    override func viewDidLoad() { 
     super.viewDidLoad() 


     // API key of the cloud application 
     _ = Indoors(licenseKey: "My_API_KEY" , andServiceDelegate: nil) 
     _indoorsSurfaceViewController = ISIndoorsSurfaceViewController() 
     _indoorsSurfaceViewController!.delegate = self 


     // Enabling dotOnRail Mode 
     _indoorsSurfaceViewController!.surfaceView.dotOnRailsJumpingDistance = 55000 
     _indoorsSurfaceViewController!.surfaceView.enableDotOnRails = true 


     // show currunt postion 
     _indoorsSurfaceViewController!.surfaceView.showsUserPosition = true 




     // Load the map in a view holding it 
     addSurfaceAsChildViewController() 
     _indoorsSurfaceViewController!.loadBuildingWithBuildingId(MyBuildingId) 


     // Route snaping 
     Indoors.instance().enablePredefinedRouteSnapping() 


     // Display All Zones 
     _indoorsSurfaceViewController!.surfaceView.setZoneDisplayMode(IndoorsSurfaceZoneDisplayModeAllAvailable) 


     // Set visible map 
     let mapRect: CGRect = _indoorsSurfaceViewController!.surfaceView.visibleMapRect 
     _indoorsSurfaceViewController!.surfaceView.setVisibleMapRect(mapRect, animated: true) 


     // Filters 
     Indoors.instance().enableStabilisationFilter = true 
     Indoors.instance().stabilisationFilterTime = 4000 



    } 







// Add the map to the view controller 
func addSurfaceAsChildViewController() { 
    self.addChildViewController(_indoorsSurfaceViewController!) 
    //_indoorsSurfaceViewController!.view.frame = self.view.frame 
    _indoorsSurfaceViewController!.view.frame = CGRectMake(0 , 0, self.view.frame.width, self.view.frame.height * 0.7) 

    self.view.addSubview(_indoorsSurfaceViewController!.view) 
    _indoorsSurfaceViewController!.didMoveToParentViewController(self) 
} 


func buildingLoaded(building : IDSBuilding!) { 
    _currentBuilding = building 
    self.calculateRoute(_currentBuilding) 
    print("@@@@@@@@@@@@@@@@@@") 
} 


func calculateRoute(building : IDSBuilding!) { 
    let start = IDSCoordinate(x: 1, andY: 111, andFloorLevel: 0); 
    let end = IDSCoordinate(x: 1, andY: 111, andFloorLevel: 0); 
    let path = [start, end] 


    Indoors.instance().routeFromLocation(start, toLocation: end, inBuilding: building, delegate: self) 
    self.setRoute(path) 

} 

// MARK: RoutingDelegate 

func setRoute(path: [AnyObject]!) { 
    _indoorsSurfaceViewController!.surfaceView.showPathWithPoints(path) 
} 



} 

擴展視圖控制器{// MARK:ISIndoorsSurfaceViewControllerDelegate

func indoorsSurfaceViewController(indoorsSurfaceViewController: ISIndoorsSurfaceViewController!, isLoadingBuildingWithBuildingId buildingId: UInt, progress: UInt) { 
    NSLog("Building loading progress: %lu", progress) 
} 

func indoorsSurfaceViewController(indoorsSurfaceViewController: ISIndoorsSurfaceViewController!, didFinishLoadingBuilding building: IDSBuilding!) { 
    NSLog("Building loaded successfully!") 

    // By Mohammed Hassan 
    UIAlertView(title: "Indoors", message: "Building loaded successfully!", delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "ok").show() 




} 

func indoorsSurfaceViewController(indoorsSurfaceViewController: ISIndoorsSurfaceViewController!, didFailLoadingBuildingWithBuildingId buildingId: UInt, error: NSError!) { 
    NSLog("Loading building failed with error: %@", error) 

    UIAlertView(title: error!.localizedDescription, message: error!.localizedFailureReason!, delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "ok").show() 
} 

// MARK: IndoorsServiceDelegate 

func onError(indoorsError: IndoorsError!) { 

} 

func locationAuthorizationStatusDidChange(status: IDSLocationAuthorizationStatus) { 




} 

func bluetoothStateDidChange(bluetoothState: IDSBluetoothState) { 


} 



} 

回答

1

您鏈接顯示,分不是整數的簡單數組(這將是奇怪的,IMO)的文檔。你將數組點轉換爲AnyObjects數組(仍然不是點,因爲你使用了整數,它將無法工作),並通過它。你需要構造一個IDSCoordinate的數組(用於開始和結束)以用作路徑。像文檔建議(轉換爲SWIFT):

var start = IDSCoordinate(x: 1234, andY: 1234, andFloorLevel: 0) 
var end = IDSCoordinate(x: 12345, andY: 12345, andFloorLevel: 0) 
// 1234 and so on are example values, that depends on your context 

Indoors.instance().routeFromLocation(start, toLocation: end, delegate: self) 

我還沒有使用的SDK(雖然我知道從indoo.rs,漂亮的夥計們的傢伙),所以我不知道什麼時候該委託方法setRoute正確調用,文檔示例似乎更新視圖以顯示路徑。

編輯:我刪除了我的例子setRoute通話,因爲在第二個想法,我開始想知道爲什麼你叫擺在首位此委託方法。對於委託方法來說,這是一個錯誤的名稱(更像是一個setter),但是如果我正確地理解了這些文檔,那麼對於而言,這稱爲,因此它是委託方法。你應該打電話給Indoors.instance().routeFromLocation(start, toLocation: end, delegate: self)。我假設,然後在某個時間點打電話給你的代表setRoute

+0

我複製了完整的代碼..謝謝你的努力 –

+0

不客氣。我無法自己嘗試,但看起來你不應該自己調用'setRoute'。一個委託方法的名字真的很糟糕,它應該像'delegateDidSetRoute'這樣的東西。我建議設置一個斷點並確保它在'Indoors.instance().'後面被調用,以確保調用'routeFromLocation(start,toLocation:end,inBuilding:building,delegate:self)'。你也可以確保'Indoors.instance()'正常工作,並給出任何實例應該是。 – Gero

+0

有一個名爲RoutingDelegate的代表,我確認了它 –

相關問題