对于我的应用程序中的导航功能,我正在使用Mapbox SDK。以下是我正在使用的代码段。

func showNavigationMap() {

    let origin = Waypoint(coordinate: currentLocation.coordinate, name: "Your Location")

    guard pickUpCoordinate != nil, dropOffCoordinate != nil else {
        showAlertMessage("Locations not generated")
        return
    }

    let pickUpLocation = Waypoint(coordinate: pickUpCoordinate, name: "Pickup Location")
    let deliveryLocation = Waypoint(coordinate: dropOffCoordinate, name: "Delivery Location")

    let options = NavigationRouteOptions(waypoints: [origin, pickUpLocation, deliveryLocation])

    Directions.shared.calculate(options) { (waypoints, routes, error) in
        guard let route = routes?.first else {
            self.showAlertMessage("No possible routes detected")
            return
        }

        self.mapNavigationViewController = NavigationViewController(for: route)

        self.mapNavigationViewController.delegate = self

        self.present(self.mapNavigationViewController, animated: true, completion: {
            print("Navigation shown")
        })
    }
}

示例屏幕如下所示。

ios - 如何在Mapbox中更改目的地以外的位置的标记?-LMLPHP

第一个停止位置显示为“1”。我希望此位置由一些自定义标记图像表示。我已经尝试了mapbox文档(https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/)。但是,我只能更改目标标记。是否可以将标记更改为所需位置?

最佳答案

这是解决方法,我已经对其进行了测试,并且可以正常工作。

extension NavigationManager: NavigationViewControllerDelegate {

  public func navigationViewController(_ navigationViewController: NavigationViewController, waypointStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
    let waypointStyleLayer = MGLCircleStyleLayer(identifier: identifier, source: source)

    // Way to custom waypoint style
    //waypointStyleLayer.circleColor = NSExpression(forConstantValue: UIColor.yellow)
    //waypointStyleLayer.circleRadius = NSExpression(forConstantValue: 12)
    //waypointStyleLayer.circleStrokeColor = NSExpression(forConstantValue: UIColor.black)
    //waypointStyleLayer.circleStrokeWidth = NSExpression(forConstantValue: 2)

    // Hides waypoint
    waypointStyleLayer.circleOpacity = NSExpression(forConstantValue: 0)
    waypointStyleLayer.circleStrokeOpacity = NSExpression(forConstantValue: 0)

    return waypointStyleLayer
  }

  public func navigationViewController(_ navigationViewController: NavigationViewController, waypointSymbolStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
    let waypointSymbolStyleLayer = MGLSymbolStyleLayer(identifier: identifier, source: source)

    // Way to custom waypoint symbol
    //waypointSymbolStyleLayer.text = NSExpression(forKeyPath: "title")
    //waypointSymbolStyleLayer.textColor = NSExpression(forConstantValue: UIColor.white)

    return waypointSymbolStyleLayer
  }

}

引用:
https://github.com/mapbox/mapbox-navigation-ios/issues/1893

关于ios - 如何在Mapbox中更改目的地以外的位置的标记?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53332100/

10-14 21:39