我使用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) {
}
}
我複製了完整的代碼..謝謝你的努力 –
不客氣。我無法自己嘗試,但看起來你不應該自己調用'setRoute'。一個委託方法的名字真的很糟糕,它應該像'delegateDidSetRoute'這樣的東西。我建議設置一個斷點並確保它在'Indoors.instance().'後面被調用,以確保調用'routeFromLocation(start,toLocation:end,inBuilding:building,delegate:self)'。你也可以確保'Indoors.instance()'正常工作,並給出任何實例應該是。 – Gero
有一個名爲RoutingDelegate的代表,我確認了它 –