我目前正在通过该API依次使用POI跟踪功能和导航。我已经注意到,API似乎仅检测准确放置在道路上的POI。

我认为这可能是由于我已实例化的SKTrackableRule:

let rule: SKTrackablePOIRule = SKTrackablePOIRule()
    rule.aerialDistance = 100
    poiTracker = SKPOITracker()
    poiTracker.dataSource = self
    poiTracker.delegate = self
    poiTracker.setRule(rule, forPOIType: 0)
    poiTracker.setRule(rule, forPOIType: kTrackablePOITypeIncident)
    poiTracker.startPOITrackerWithRadius(kRadius, refreshMargin: kRefreshMargin, forPOITypes: [0])

我已经在http://sdkblog.skobbler.com/detecting-tracking-pois-in-your-way/上阅读了该规则的参数:
rule.routeDistance

具有默认值。我想如果未在道路上放置POI,则无法实现此参数,因为API无法找到从用户位置到POI的任何道路。
我的问题是:
这是否意味着始终需要在道路上放置POI?如果是这样,是否可以停用此参数?

感谢任何尝试解决此问题的人。

这是我的完整代码:
var map: SKMapView!

var poiTracker: SKPOITracker!
var trackablePOIs: Array<SKTrackablePOI>! = []

//Parcourt Informations Touristiques
var TableauPOIParcourues: Array<ParcourtPoi>! = []
var IndicateurPlaceTableau: Int = 0;


//utilisé pour charger le fichier GPX
var datasource: Array<AnyObject>!
var fileName: String!
var titreRoute: String!



//MARK: Lifecycle
override func viewDidLoad() {
    super.viewDidLoad()


    //Pour initialiser les variables de lecture audio

    self.configureAudioPlayer()
    NSLog("Nombre de POI en mémoire :" + String(trackablePOIs.count))
    //Pour mettre en évidence la vue direction sur la vue Map
    MapView.hidden = false
    DirectionView.hidden = true

    //paramétrage de la carte
    map = SKMapView(frame: CGRectMake(0.0, 0.0, CGRectGetWidth(DirectionView.frame), CGRectGetHeight(DirectionView.frame))) //défini la zone de la carte suivant la view Direction
    map.delegate = self
    map.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
    map.settings.followUserPosition = false
    map.mapScaleView.hidden = true
    map.settings.headingMode = SKHeadingMode.RotatingHeading


    trackablePOIs = self.trackablePOIsForDemo()



    DirectionView.addSubview(self.map)
    let region: SKCoordinateRegion = SKCoordinateRegion(center: CLLocationCoordinate2DMake(49.61043, 6.13294), zoomLevel: 17)
    map.visibleRegion = region

    self.chargementNavigation()

}

//MARK: Private methods

private func chargementNavigation() {

    SKRoutingService.sharedInstance().navigationDelegate = self
    SKRoutingService.sharedInstance().routingDelegate = self
    SKRoutingService.sharedInstance().mapView = map
    NSLog("nom du fichier gpx: " + fileName)
    NSLog(NSBundle.mainBundle().pathForResource(fileName, ofType: "gpx")!)
    let path: String = NSBundle.mainBundle().pathForResource(fileName, ofType: "gpx")!
    NSLog("chemin du fichier" + path)

    do {

        let root: SKGPSFileElement = try SKGPSFilesService.sharedInstance().loadFileAtPath(path)
        let tablePointGPX: Array<AnyObject> = SKGPSFilesService.sharedInstance().locationsForElement(root)
        let routeSetting = SKRouteSettings()

        routeSetting.shouldBeRendered = true
        routeSetting.requestAdvices = true
        routeSetting.routeMode = SKRouteMode.Pedestrian
        routeSetting.routeConnectionMode = SKRouteConnectionMode.Offline

        self.startPOITracking()
        self.addAnnotations()
        SKRoutingService.sharedInstance().calculateRouteWithSettings(routeSetting, customLocations: tablePointGPX)
    } catch let error as NSError {
    }

}


override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    poiTracker.stopPOITracker()
    map.settings.displayMode = SKMapDisplayMode.Mode2D

    AudioService.sharedInstance().cancel()

    SKRoutingService.sharedInstance().clearAllRoutesFromCache()
    SKRoutingService.sharedInstance().clearCurrentRoutes()
    SKRoutingService.sharedInstance().stopNavigation()

    self.removeAnnotations()
}


// MARK : Audio configuration

private func configureAudioPlayer() {
    let mainBundlePath: String = NSBundle.mainBundle().resourcePath! + ("/SKAdvisorResources.bundle")
    let advisorResourcesBundle: NSBundle =  NSBundle(path:mainBundlePath)!
    let soundFilesFolder: String = advisorResourcesBundle.pathForResource("Languages", ofType: "")!
    let currentLanguage: String = "en"
    let audioFilesFolderPath: String = soundFilesFolder + "/" +  currentLanguage + "/" + "sound_files"+"/"

    AudioService.sharedInstance().audioFilesFolderPath = audioFilesFolderPath
    let settings: SKAdvisorSettings = SKAdvisorSettings()
    settings.advisorVoice = currentLanguage
    SKRoutingService.sharedInstance().advisorConfigurationSettings = settings
}


// MARK : POI Tracker

private func startPOITracking() {
    let rule: SKTrackablePOIRule = SKTrackablePOIRule()
    rule.aerialDistance = 200
    poiTracker = SKPOITracker()
    poiTracker.dataSource = self
    poiTracker.delegate = self
    poiTracker.setRule(rule, forPOIType: 0)
    poiTracker.setRule(rule, forPOIType: kTrackablePOITypeIncident)
    poiTracker.startPOITrackerWithRadius(kRadius, refreshMargin: kRefreshMargin, forPOITypes: [0])
}
private func trackablePOIsForDemo() -> Array<SKTrackablePOI>! {

    //ciné caluire
    let trackablePOI1: SKTrackablePOI = SKTrackablePOI()
    trackablePOI1.poiID = 0
    trackablePOI1.type = 0
    trackablePOI1.heading = -1
    trackablePOI1.coordinate = CLLocationCoordinate2DMake(45.804819, 4.853232)

    //OKI Impression
    let trackablePOI2: SKTrackablePOI = SKTrackablePOI()
    trackablePOI2.poiID = 1
    trackablePOI2.type = 0
    trackablePOI2.heading = -1
    trackablePOI2.coordinate = CLLocationCoordinate2DMake(45.805761, 4.851612)


    //Résidence de la tour
    let trackablePOI3: SKTrackablePOI = SKTrackablePOI()
    trackablePOI3.poiID = 2
    trackablePOI3.heading = -1
    trackablePOI3.type = 0
    trackablePOI3.coordinate = CLLocationCoordinate2DMake(45.803787, 4.85173)

    //La chambre funéraire
    let trackablePOI4: SKTrackablePOI = SKTrackablePOI()
    trackablePOI4.poiID = 3
    trackablePOI4.type = 0
    trackablePOI4.coordinate = CLLocationCoordinate2DMake(45.802717, 4.851311)

    //La paroisse catholique
    let trackablePOI5: SKTrackablePOI = SKTrackablePOI()
    trackablePOI5.poiID = 4
    trackablePOI5.type = 0
    trackablePOI5.coordinate = CLLocationCoordinate2DMake(45.799935, 4.848114)

    //Cimetière de Caluire
    let trackablePOI6: SKTrackablePOI = SKTrackablePOI()
    trackablePOI6.poiID = 5
    trackablePOI6.type = 0
    trackablePOI6.coordinate = CLLocationCoordinate2DMake(45.80084,  4.851462)

    //La voie verte
    let trackablePOI7: SKTrackablePOI = SKTrackablePOI()
    trackablePOI7.poiID = 6
    trackablePOI7.type = kTrackablePOITypeIncident
    trackablePOI7.coordinate = CLLocationCoordinate2DMake(45.806771,  4.858146)

    //Beginning
    let trackablePOI8: SKTrackablePOI = SKTrackablePOI()
    trackablePOI8.poiID = 7
    trackablePOI8.heading = -1
    trackablePOI8.type = kTrackablePOITypeIncident
    trackablePOI8.coordinate = CLLocationCoordinate2DMake(49.61043,  6.13294)

    //Grand ducal palace
    let trackablePOI9: SKTrackablePOI = SKTrackablePOI()
    trackablePOI9.poiID = 8
    trackablePOI9.heading = -1
    trackablePOI9.type = kTrackablePOITypeIncident
    trackablePOI9.coordinate = CLLocationCoordinate2DMake(49.610978,  6.132507)

    //Gelle Fra
    let trackablePOI10: SKTrackablePOI = SKTrackablePOI()
    trackablePOI10.poiID = 9
    trackablePOI10.heading = -1
    trackablePOI10.type = kTrackablePOITypeIncident
    trackablePOI10.coordinate = CLLocationCoordinate2DMake(49.609273999,  6.12935630)

    //Square william 2
    let trackablePOI11: SKTrackablePOI = SKTrackablePOI()
    trackablePOI11.poiID = 10
    trackablePOI11.heading = -1
    trackablePOI11.type = kTrackablePOITypeIncident
    trackablePOI11.coordinate = CLLocationCoordinate2DMake(49.610418,  6.131728)

    //Adolph's bridge
    let trackablePOI12: SKTrackablePOI = SKTrackablePOI()
    trackablePOI12.poiID = 11
    trackablePOI12.heading = -1
    trackablePOI12.heading = -1
    trackablePOI12.type = kTrackablePOITypeIncident
    trackablePOI12.coordinate = CLLocationCoordinate2DMake(49.608271,6.126431)

    //Neumünster Abbay
    let trackablePOI13: SKTrackablePOI = SKTrackablePOI()
    trackablePOI13.poiID = 12
    trackablePOI13.heading = -1
    trackablePOI13.type = kTrackablePOITypeIncident
    trackablePOI13.coordinate = CLLocationCoordinate2DMake(0, 0)

    //Bock's Casemates
    let trackablePOI14: SKTrackablePOI = SKTrackablePOI()
    trackablePOI14.poiID = 13
    trackablePOI14.heading = -1
    trackablePOI14.type = kTrackablePOITypeIncident
    trackablePOI14.coordinate = CLLocationCoordinate2DMake(49.611595, 6.13659)
    //Casemates
    let trackablePOI15: SKTrackablePOI = SKTrackablePOI()
    trackablePOI15.poiID = 14
    trackablePOI15.heading = -1
    trackablePOI15.type = kTrackablePOITypeIncident
    trackablePOI15.coordinate = CLLocationCoordinate2DMake(49.611595, 6.13659)
    //Thüngen fort
    let trackablePOI16: SKTrackablePOI = SKTrackablePOI()
    trackablePOI16.poiID = 15
    trackablePOI16.heading = -1
    trackablePOI16.type = kTrackablePOITypeIncident
    trackablePOI16.coordinate = CLLocationCoordinate2DMake(49.616975, 6.140209)
    //Septfontaines castle
    let trackablePOI17: SKTrackablePOI = SKTrackablePOI()
    trackablePOI17.poiID = 16
    trackablePOI17.heading = -1
    trackablePOI17.type = kTrackablePOITypeIncident
    trackablePOI17.coordinate = CLLocationCoordinate2DMake(49.625711 , 6.10505)
    //Saint quirin chapel
    let trackablePOI18: SKTrackablePOI = SKTrackablePOI()
    trackablePOI18.poiID = 17
    trackablePOI18.heading = -1
    trackablePOI18.type = kTrackablePOITypeIncident
    trackablePOI18.coordinate = CLLocationCoordinate2DMake(49.60571, 6.13528)
    //Pétrusse Valley
    let trackablePOI19: SKTrackablePOI = SKTrackablePOI()
    trackablePOI19.poiID = 18
    trackablePOI19.heading = -1
    trackablePOI19.type = kTrackablePOITypeIncident
    trackablePOI19.coordinate = CLLocationCoordinate2DMake(49.607519, 6.12551)
    //jews door
    let trackablePOI20: SKTrackablePOI = SKTrackablePOI()
    trackablePOI20.poiID = 19
    trackablePOI20.heading = -1
    trackablePOI20.type = kTrackablePOITypeIncident
    trackablePOI20.coordinate = CLLocationCoordinate2DMake(49.610418, 6.131728)
    //Mudam
    let trackablePOI21: SKTrackablePOI = SKTrackablePOI()
    trackablePOI21.poiID = 20
    trackablePOI21.heading = -1
    trackablePOI21.type = kTrackablePOITypeIncident
    trackablePOI21.coordinate = CLLocationCoordinate2DMake(49.617095, 6.140337)
    //Grund
    let trackablePOI22: SKTrackablePOI = SKTrackablePOI()
    trackablePOI22.poiID = 21
    trackablePOI22.heading = -1
    trackablePOI22.type = kTrackablePOITypeIncident
    trackablePOI22.coordinate = CLLocationCoordinate2DMake(49.608189, 6.135507)
    //The Alzette river
    let trackablePOI23: SKTrackablePOI = SKTrackablePOI()
    trackablePOI23.poiID = 22
    trackablePOI23.heading = -1
    trackablePOI23.type = kTrackablePOITypeIncident
    trackablePOI23.coordinate = CLLocationCoordinate2DMake(49.610432, 6.135494)
    //The Pétrusse river
    let trackablePOI24: SKTrackablePOI = SKTrackablePOI()
    trackablePOI24.poiID = 23
    trackablePOI24.heading = -1
    trackablePOI24.type = kTrackablePOITypeIncident
    trackablePOI24.coordinate = CLLocationCoordinate2DMake(49.607519, 6.125516)
    //Spuerkess head offices
    let trackablePOI25: SKTrackablePOI = SKTrackablePOI()
    trackablePOI25.poiID = 24
    trackablePOI25.heading = -1
    trackablePOI25.type = kTrackablePOITypeIncident
    trackablePOI25.coordinate = CLLocationCoordinate2DMake(49.607054, 6.128070)
    //Arbed head offices
    let trackablePOI26: SKTrackablePOI = SKTrackablePOI()
    trackablePOI26.poiID = 25
    trackablePOI26.heading = -1
    trackablePOI26.type = kTrackablePOITypeIncident
    trackablePOI26.coordinate = CLLocationCoordinate2DMake(0,0)
    //Place d'armes
    let trackablePOI27: SKTrackablePOI = SKTrackablePOI()
    trackablePOI27.poiID = 26
    trackablePOI27.heading = -1
    trackablePOI27.type = kTrackablePOITypeIncident
    trackablePOI27.coordinate = CLLocationCoordinate2DMake(49.611306, 6.129408)
    //Philarmonie
    let trackablePOI28: SKTrackablePOI = SKTrackablePOI()
    trackablePOI28.poiID = 27
    trackablePOI28.heading = -1
    trackablePOI28.type = kTrackablePOITypeIncident
    trackablePOI28.coordinate = CLLocationCoordinate2DMake(49.618602, 6.142702)
    //European parliament
    let trackablePOI29: SKTrackablePOI = SKTrackablePOI()
    trackablePOI29.poiID = 28
    trackablePOI29.heading = -1
    trackablePOI29.type = kTrackablePOITypeIncident
    trackablePOI29.coordinate = CLLocationCoordinate2DMake(49.621613, 6.14676)
    //The European Court of Auditors
    let trackablePOI30: SKTrackablePOI = SKTrackablePOI()
    trackablePOI30.poiID = 29
    trackablePOI30.heading = -1
    trackablePOI30.type = kTrackablePOITypeIncident
    trackablePOI30.coordinate = CLLocationCoordinate2DMake(49.623004, 6.149332)
    //European Investment Fund
    let trackablePOI31: SKTrackablePOI = SKTrackablePOI()
    trackablePOI31.poiID = 30
    trackablePOI31.heading = -1
    trackablePOI31.type = kTrackablePOITypeIncident
    trackablePOI31.coordinate = CLLocationCoordinate2DMake(49.628933, 6.164587)
    //European Investment Bank
    let trackablePOI32: SKTrackablePOI = SKTrackablePOI()
    trackablePOI32.poiID = 31
    trackablePOI32.heading = -1
    trackablePOI32.type = kTrackablePOITypeIncident
    trackablePOI32.coordinate = CLLocationCoordinate2DMake(49.622144, 6.140124)

    //Court of justice
    let trackablePOI33: SKTrackablePOI = SKTrackablePOI()
    trackablePOI33.poiID = 32
    trackablePOI33.heading = -1
    trackablePOI33.type = kTrackablePOITypeIncident
    trackablePOI33.coordinate = CLLocationCoordinate2DMake(49.61919, 6.140891)




    return [trackablePOI1, trackablePOI2, trackablePOI3, trackablePOI4, trackablePOI5, trackablePOI6, trackablePOI7, trackablePOI8, trackablePOI9, trackablePOI10, trackablePOI11, trackablePOI12, trackablePOI13, trackablePOI14, trackablePOI15, trackablePOI16, trackablePOI17, trackablePOI18, trackablePOI19, trackablePOI20, trackablePOI21, trackablePOI22, trackablePOI23, trackablePOI24, trackablePOI25, trackablePOI26, trackablePOI27, trackablePOI28, trackablePOI29, trackablePOI30, trackablePOI31, trackablePOI32]

}

private func addAnnotations() {
    let animationSettings: SKAnimationSettings = SKAnimationSettings()
    for poi: SKTrackablePOI in trackablePOIs {

        let coloredView = UIImageView(frame: CGRectMake(0.0, 0.0, 32.0, 32.0))
        coloredView.image = UIImage(named: "map-position-64.png")

        //create the SKAnnotationView
        let view = SKAnnotationView(view: coloredView, reuseIdentifier: "viewID")

        //create the annotation
        let viewAnnotation = SKAnnotation()
        //set the custom view
        viewAnnotation.annotationView = view
        viewAnnotation.identifier = poi.poiID
        viewAnnotation.location = poi.coordinate

        //NSLog("Ajout visuelle id " + String(poi.poiID))

        map.addAnnotation(viewAnnotation, withAnimationSettings: animationSettings)
    }
}

private func removeAnnotations() {
    map.clearAllAnnotations()
}

//MARK : SKPOITrackerDataSource

func poiTracker(poiTracker: SKPOITracker!, trackablePOIsAroundLocation location: CLLocationCoordinate2D, inRadius radius: Int32, withType poiType: Int32) -> [AnyObject]! {
    return self.trackablePOIs
}

func poiTracker(poiTracker: SKPOITracker!, didDectectPOIs detectedPOIs: [AnyObject]!, withType type: Int32) {
    //NSLog("Détection d'un POI")
    for poi in detectedPOIs as! Array<SKDetectedPOI> {
        NSLog(poi.description)
    }
}

//MARK : RoutingService

func routingService(routingService: SKRoutingService!, didFinishRouteCalculationWithInfo routeInformation: SKRouteInformation!) {
    routingService.zoomToRouteWithInsets(UIEdgeInsetsZero, duration:1)

    let navSettings = SKNavigationSettings()
    navSettings.navigationType = SKNavigationType.Simulation
    navSettings.transportMode = SKTransportMode.Pedestrian
    navSettings.distanceFormat = SKDistanceFormat.Metric
    navSettings.showStreetNamePopUpsOnRoute = true
    SKRoutingService.sharedInstance().mainRouteId = routeInformation.routeID
    SKRoutingService.sharedInstance().mapView!.settings.displayMode = SKMapDisplayMode.Mode2D
    SKRoutingService.sharedInstance().startNavigationWithSettings(navSettings)
}

func routingService(routingService: SKRoutingService!, didChangeDistanceToDestination distance: Int32, withFormattedDistance formattedDistance: String!) {
}


func routingServiceDidReachDestination(routingService: SKRoutingService!) {

    SKRoutingService.sharedInstance().stopNavigation()
    poiTracker.stopPOITracker()
}

func routingService(routingService: SKRoutingService!, didChangeCurrentAdvice currentAdvice: SKRouteAdvice!, isLastAdvice: Bool) {
    //NSLog(currentAdvice.adviceInstruction)
}

func routingService(routingService: SKRoutingService!, didChangeCurrentSpeed speed: Double) {

}

func routingService(routingService: SKRoutingService!, didChangeCurrentVisualAdviceDistance distance: Int32, withFormattedDistance formattedDistance: String!) {
}


func routingService(routingService: SKRoutingService!, didChangeNextStreetName nextStreetName: String!, streetType: SKStreetType, countryCode: String!) {
}

func routingService(routingService: SKRoutingService!, didChangeCurrentAdviceImage adviceImage: UIImage!, withLastAdvice isLastAdvice: Bool) {

}


func routingService(routingService: SKRoutingService!, didUpdateFilteredAudioAdvices audioAdvices: [AnyObject]!) {
}

//MARK : CoreData

}

最佳答案

这是您的SKTrackablePOIRule的外观:
let rule: SKTrackablePOIRule = SKTrackablePOIRule() rule.aerialDistance = 100
rule.routeDistance = 1500 rule.numberOfTurns = 2

rule.maxGPSAccuracy = 100

rule.minSpeedIgnoreDistanceAfterTurn = 80

rule.maxDistanceAfterTurn = 300 rule.eliminateIfUTurn = YES

rule.playAudioWarning= NO

查看文档(SKTrackablePOIRule),并考虑应满足所有所有规则。

[编辑:28-03-2016]:在演示应用程序中,我们添加了example with some POIs和未放置在道路上的POITrackerViewController class(也请查看更新的ojit_a),一切正常。

关于ios - 越野追踪POI,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35817103/

10-13 03:57