AR навигации Google поворот за поворотом текст неуместны в iOS Xcode? - PullRequest
0 голосов
/ 19 декабря 2018

Я работаю с навигацией на улице, используя Google Navigation.Направлено [git@github.com:rakshithaacharymedia/ARNavigation.git][1] для навигации Google.Из этого примера я могу показать путь и направление текста.Но текст направления не отображается от источника к месту назначения.

Текст направления AR не отображается, показывая от источника к месту назначения.его показы перед узлом источника.

Вот класс модели для получения шагов промежуточного узла:

  struct Step {
var distance: String = ""
var duration: String = ""
var endLocation: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
var locationName: String = ""

func intermediateRouteInfo(_ leg: [String: Any]) -> [Step] {
    var steps = [Step] ()
    for step in leg[ApiResponseConstant.steps] as? [[String: Any]] ?? [[ :]] {
        if let location = step[ApiResponseConstant.end_location] as? [String: Any], let distance = step[ApiResponseConstant.distance] as? [String: Any], let duration = step[ApiResponseConstant.duration] as? [String: Any], let name = step[ApiResponseConstant.html_instructions] as? String {
            if let lat = location[ApiResponseConstant.lat] as? CLLocationDegrees, let lng = location[ApiResponseConstant.lng] as? CLLocationDegrees, let distanceText = distance[ApiResponseConstant.text] as? String, let durationText = duration[ApiResponseConstant.text] as? String {
                steps.append(Step(distance: distanceText, duration: durationText, endLocation: CLLocationCoordinate2D(latitude: lat, longitude: lng), locationName: ((name).html2String)))
            }
        }
     }
     return steps
    }
  }

Вот код для текста направления ar:

       private func arViewSetup() {

    if let source = source, let destination = destination {
        for intermediateLocation in stepData.enumerated() {
            print("directionss \(TextNodeConstant.direction), intermediate locations \(intermediateLocation.element.locationName)")
            var text = "\(TextNodeConstant.direction) : " + intermediateLocation.element.locationName
            text += "\n \(TextNodeConstant.distance) :" + intermediateLocation.element.distance
            text += " \n \(TextNodeConstant.duration) : " + intermediateLocation.element.duration
            placeDestinationNode(source: source, destination: intermediateLocation.element.endLocation, text: text, directionName: intermediateLocation.element.locationName)
        }
        placeDestinationNode(source: source, destination: destination, text: TextNodeConstant.destination, directionName: TextNodeConstant.direction)
    }
      placeSourceNode()
}

Вот код для рисования пути ar от источника к месту назначения вместе с текстом направления и изображением направления:

       private func placeSourceNode() {
    let box = SCNBox(width: ArkitNodeDimension.sourceNodeWidth, height: ArkitNodeDimension.sourceNodeHeight, length: ArkitNodeDimension.sourceNodeLength, chamferRadius: ArkitNodeDimension.sourceChamferRadius)
    let sourceNode = SCNNode(geometry: box)
    sourceNode.geometry?.firstMaterial?.diffuse.contents = UIColor.clear
    sourceNode.position = SCNVector3(0, -(ArkitNodeDimension.nodeYPosition), 0)
    sceneView.scene.rootNode.addChildNode(sourceNode)
}

private func distanceBetweenCordinate(source: CLLocationCoordinate2D, destination: CLLocationCoordinate2D) -> Double {
    let sourceLocation = CLLocation(latitude: source.latitude, longitude: source.longitude)
    let destinationLocation = CLLocation(latitude: destination.latitude, longitude: destination.longitude)
    let distance = sourceLocation.distance(from: destinationLocation)
    return distance
}

private func placeDestinationNode(source: CLLocationCoordinate2D, destination: CLLocationCoordinate2D, text: String,directionName : String) {
    print("direction name:::\(directionName)")
    let distance = distanceBetweenCordinate(source: source, destination: destination)
    let destinationNode = SCNNode(geometry: intermediateNodeGeometry(directions: text))

    let  transformationMatrix = transformMatrix(source: source, destination: destination, distance: distance, text: text)
    destinationNode.transform = transformationMatrix
    sceneView.scene.rootNode.addChildNode(destinationNode)
    placeCylinder(source: sourcePosition, destination: destinationNode.position)
    let directionTextNode = placeDirectionText(textPosition: destinationNode.position, text: text)
    destinationNode.addChildNode(directionTextNode)
    let directionNodeImage = SCNNode(geometry: intermediateDirectionNode(directionElement: directionName))
    directionNodeImage.position = SCNVector3(0, 1, 0)
    destinationNode.addChildNode(directionNodeImage)
     let overlayMarkerNode = self.getNode(withImageName: "3dMarker")
    print("3d name:::\(overlayMarkerNode)")
    destinationNode.addChildNode(overlayMarkerNode)
    sourcePosition = destinationNode.position
}



private func intermediateDirectionNode(directionElement: String) -> SCNBox {
    // intermediateBox for direction

    let intermediatePlane = SCNBox(width: 0.9, height: 0.9, length: 0.001, chamferRadius: 0)


    if directionElement == "Turn left" {

        intermediatePlane.firstMaterial?.diffuse.contents = UIImage(named: "turnleft")

    } else if directionElement == "Turn right" {

        intermediatePlane.firstMaterial?.diffuse.contents = UIImage(named: "turnright")

    }else if directionElement == "Head east" {

        intermediatePlane.firstMaterial?.diffuse.contents = UIColor.clear

    } else if directionElement == "Destination" {

        intermediatePlane.firstMaterial?.diffuse.contents = UIColor.clear
    }
    return intermediatePlane
}

private func intermediateNodeGeometry(directions: String) -> SCNBox {
    print("Direction node:::\(directions)")

    let intermediateBox = SCNBox(width: ArkitNodeDimension.destinationNodeWidth, height: ArkitNodeDimension.destinationNodeHeight, length: ArkitNodeDimension.destinationNodeLength, chamferRadius: ArkitNodeDimension.destinationChamferRadius)


        intermediateBox.firstMaterial?.diffuse.contents = UIColor.purple.withAlphaComponent(0.0)


    return intermediateBox
}

Моя проблема в том, что текстовый узел direciton не отображается от узла источника к узлу назначения?

...