How to change marker for locations other than destination in Mapbox?












5















For navigation feature in my app, I am using Mapbox SDK. Following is a snippet that I am using.



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")
})
}
}


The sample screen is as shown below.



enter image description here



The first stop location is indicated as "1". I would like this location to be represented by some custom marker image. I have tried the mapbox documentation (https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/). However, I could change the destination marker only. Is it possible to change the marker for the desired location?










share|improve this question





























    5















    For navigation feature in my app, I am using Mapbox SDK. Following is a snippet that I am using.



    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")
    })
    }
    }


    The sample screen is as shown below.



    enter image description here



    The first stop location is indicated as "1". I would like this location to be represented by some custom marker image. I have tried the mapbox documentation (https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/). However, I could change the destination marker only. Is it possible to change the marker for the desired location?










    share|improve this question



























      5












      5








      5








      For navigation feature in my app, I am using Mapbox SDK. Following is a snippet that I am using.



      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")
      })
      }
      }


      The sample screen is as shown below.



      enter image description here



      The first stop location is indicated as "1". I would like this location to be represented by some custom marker image. I have tried the mapbox documentation (https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/). However, I could change the destination marker only. Is it possible to change the marker for the desired location?










      share|improve this question
















      For navigation feature in my app, I am using Mapbox SDK. Following is a snippet that I am using.



      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")
      })
      }
      }


      The sample screen is as shown below.



      enter image description here



      The first stop location is indicated as "1". I would like this location to be represented by some custom marker image. I have tried the mapbox documentation (https://www.mapbox.com/ios-sdk/navigation/examples/custom-destination-marker/). However, I could change the destination marker only. Is it possible to change the marker for the desired location?







      ios swift mapbox markers






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 5 '18 at 10:24







      Sujal

















      asked Nov 16 '18 at 5:45









      SujalSujal

      649516




      649516
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Here is the workaround, I have tested it and it works.



          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
          }

          }





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






          share|improve this answer
























          • I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

            – Sujal
            Jan 16 at 11:08












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332100%2fhow-to-change-marker-for-locations-other-than-destination-in-mapbox%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Here is the workaround, I have tested it and it works.



          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
          }

          }





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






          share|improve this answer
























          • I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

            – Sujal
            Jan 16 at 11:08
















          0














          Here is the workaround, I have tested it and it works.



          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
          }

          }





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






          share|improve this answer
























          • I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

            – Sujal
            Jan 16 at 11:08














          0












          0








          0







          Here is the workaround, I have tested it and it works.



          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
          }

          }





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






          share|improve this answer













          Here is the workaround, I have tested it and it works.



          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
          }

          }





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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 14 at 11:56









          tezqatezqa

          647




          647













          • I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

            – Sujal
            Jan 16 at 11:08



















          • I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

            – Sujal
            Jan 16 at 11:08

















          I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

          – Sujal
          Jan 16 at 11:08





          I am able to change the style of the default waypoint marker with the above code, but I would like to replace it with a new custom icon. How do I achieve that?

          – Sujal
          Jan 16 at 11:08




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332100%2fhow-to-change-marker-for-locations-other-than-destination-in-mapbox%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues