I try ar navigation for outdoor. I have used mapbox for ar navigation and used mapboxarkit and mapboxDirection cocopods.
The nodes are shown as path. I can able show path as dotted shpere or plane but not able show as line. Here is my out put screenshotshere is the node, which i have tried to show as a line breaking and tried to adjuct scnbox in straight to show as line.
Result which i have expected I want ar line like this.
Here is the code i have tried so far - Here is the code to add ar annotation and ar line.
if let route = routes?.first, let leg = route.legs.first {
var polyline = [CLLocationCoordinate2D]()
// Add an AR node and map view annotation for every defined "step" in the route
for step in leg.steps {
let coordinate = step.coordinates!.first!
polyline.append(coordinate)
let stepLocation = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
// Update feature collection for map view
self.updateShapeCollectionFeature(&self.waypointShapeCollectionFeature, with: stepLocation, typeKey: "waypoint-type", typeAttribute: "big")
// Add an AR node
let annotation = Annotation(location: stepLocation, calloutImage: self.calloutImage(for: step.description))
annotationsToAdd.append(annotation)
}
let metersPerNode: CLLocationDistance = 1
let turfPolyline = Polyline(polyline)
// Walk the route line and add a small AR node and map view annotation every metersPerNode
for i in stride(from: metersPerNode, to: turfPolyline.distance() - metersPerNode, by: metersPerNode) {
// Use Turf to find the coordinate of each incremented distance along the polyline
if let nextCoordinate = turfPolyline.coordinateFromStart(distance: i) {
let interpolatedStepLocation = CLLocation(latitude: nextCoordinate.latitude, longitude: nextCoordinate.longitude)
// Update feature collection for map view
self.updateShapeCollectionFeature(&self.waypointShapeCollectionFeature, with: interpolatedStepLocation, typeKey: "waypoint-type", typeAttribute: "small")
// Add an AR node
let annotation = Annotation(location: interpolatedStepLocation, calloutImage: nil)
annotationsToAdd.append(annotation)
}
Here is the code for create scnplane:
func createLightBulbNode() -> SCNNode {
let lightBulbNode = collada2SCNNode(filepath: "art.scnassets/cubeSolid.dae")
lightBulbNode.position = SCNVector3(0, -0.5, 0)
return lightBulbNode
}
func collada2SCNNode(filepath:String) -> SCNNode {
let node = SCNNode()
let scene = SCNScene(named: filepath, inDirectory: nil, options: [SCNSceneSource.LoadingOption.animationImportPolicy: SCNSceneSource.AnimationImportPolicy.doNotPlay])
let nodeArray = scene!.rootNode.childNodes
for childNode in nodeArray {
node.addChildNode(childNode as SCNNode)
}
return node
}
}
func node(for annotation: Annotation) -> SCNNode? {
if annotation.calloutImage == nil {
// Comment `createLightBulbNode` and add `return nil` to use the default node
return createLightBulbNode()
} else {
let firstColor = UIColor(red: 0.0, green: 99/255.0, blue: 175/255.0, alpha: 1.0)
return createSphereNode(with: 0.5, firstColor: firstColor, secondColor: UIColor.green)
}
}
Any help much appreciated pls...
from How to draw line in arkit based on CLLocation in iOS Swift?
No comments:
Post a Comment