2016-08-02 3 views
0

Ich benutze Indoo.rs ios sdk von swift, um eine kleine App zu bauen, die meine Karte zeigt, das Problem ist, ich habe keine Idee, einen Code zu schreiben, Route zwischen 2 Punkt zu setzen auf der Karte, ich über die Dokumentation kam aber kein Ergebnis ... hier ist mein Code:Route auf einer Karte mit Indoo.rs ios sdk setzen

die Dokumentation ist hier: https://indoors.readme.io/docs/routing-1

Bitte, wenn es bei mir eine Idee Aktie. Dank

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



} 

Erweiterung Viewcontroller { // 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) { 


} 



} 

Antwort

1

Die Dokumentation zeigt Ihnen verbunden, dass die Punkte sind nicht einfache Arrays von ganzen Zahlen (das wäre seltsam, imo). Sie werfen den Array-Punkt auf ein Array von AnyObjects (immer noch keine Punkte, und da Sie ganze Zahlen verwendet haben, wird es sowieso nicht funktionieren) und übergeben das. Sie müssen ein Array von IDSCoordinate s (für Anfang und Ende) erstellen, das als Pfad verwendet wird. Wie die Dokumentation (zu raschen umgewandelt) schlägt vor:

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) 

Ich habe nicht das SDK verwendet (obwohl ich die Jungs von indoo.rs, schönen fellas wissen), damit ich weiß nicht, wann das Delegatmethode setRoute wird genau aufgerufen, das Dokumentationsbeispiel scheint eine Ansicht zu aktualisieren, um den Pfad anzuzeigen.

Bearbeiten: Ich löschte die setRoute Aufruf in meinem Beispiel, denn auf den zweiten Gedanken begann ich zu fragen, warum Sie diese Delegate-Methode in erster Linie aufgerufen haben. Es ist ein schlechter Name für eine Delegate-Methode, true (mehr wie ein Setter), aber wenn ich die Dokumentation richtig verstehe, heißt dies für Sie, daher ist es eine Delegate-Methode. Sie sollten Indoors.instance().routeFromLocation(start, toLocation: end, delegate: self) anrufen. Ich nehme an, dass irgendwann dann Ihr Delegierter setRoute anruft.

+0

Ich kopierte den vollständigen Code .. Danke Mann für Ihre Mühe –

+0

Gern geschehen. Ich kann es nicht selbst ausprobieren, aber es sieht wirklich so aus, als ob du 'setRoute' nicht selbst nennen solltest. Ein wirklich schlechter Name für eine Delegate-Methode, sollte etwas wie 'delegateDidSetRoute' oder so sagen. Ich schlage vor, einen Haltepunkt zu setzen und sicherzustellen, dass er nach 'Indoors.instance(). RouteFromLocation (start, toLocation: end, inBuilding: building, delegate: self) aufgerufen wird, um sicherzugehen. Sie können auch sicherstellen, dass 'Indoors.instance()' richtig funktioniert und gibt, was auch immer die Instanz sein soll. – Gero

+0

Es gibt einen Delegaten namens RoutingDelegate, den ich bestätigt habe –

Verwandte Themen