Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes Not Showing for Globe #2184

Closed
petermulsh opened this issue May 18, 2024 · 1 comment
Closed

Routes Not Showing for Globe #2184

petermulsh opened this issue May 18, 2024 · 1 comment
Labels
bug 🪲 Something is broken!

Comments

@petermulsh
Copy link

Environment

  • Xcode version: 15.3
  • iOS version: 17.4.1
  • Devices affected: Iphone
  • Maps SDK Version:

Routes are not displaying on custom Map. I create the map like this. The map is a .globe made in the online editor.

guard let customStyleURI = StyleURI(rawValue: "mapbox://styles/xxxx/xxxx") else {
            fatalError("Style URI is invalid")
        }
let options = MapInitOptions(styleURI: customStyleURI)
mapView = MapView(frame: self.view.bounds, mapInitOptions: options)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.ornaments.options.scaleBar.visibility = .hidden
mapView.gestures.delegate = self
let centerCoordinate = CLLocationCoordinate2DMake(37.0902, -95.7129)
let newCamera = CameraOptions(center: centerCoordinate,
                                      padding: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: self.view.frame.size.width/2),
                                      anchor: .zero,
                                      zoom: 1.0,
                                      bearing: 0,
                                      pitch: 0)
self.view.addSubview(mapView)
mapView.camera.fly(to: newCamera, duration: 5.0, completion: { UIViewAnimatingPosition in
self.spinGlobe()
})

Then I create the route like so

let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194))
let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.7849, longitude: -122.4094))
let routeOptions = NavigationRouteOptions(waypoints: [origin, destination])
Task{
       do  {
             let routesResponse = try await navigationProvider.routingProvider().calculateRoutes(options: routeOptions).value
             let route = routesResponse.mainRoute.route
             displayRoute(route, routeId: "id")
        } catch {
              print("Error occured while requesting routes: \(error.localizedDescription)")
        }
}

And finally I try to draw it

func displayRoute(_ route: Route, routeId: String) {
        guard let routeShape = route.shape else {
              print("Route shape is nil")
              return
         }
                
        var geoJSONSource = GeoJSONSource(id: "")
        geoJSONSource.data = .geometry(.lineString(routeShape))
                
        var lineLayer = LineLayer(id: "route-layer-\(routeId)", source: "")
        lineLayer.source = routeId
        lineLayer.lineColor = .constant(StyleColor(.blue))
        lineLayer.lineWidth = .constant(5.0)
                
        do {
            try mapView.mapboxMap.addSource(geoJSONSource)
            try mapView.mapboxMap.addLayer(lineLayer)
            print("added route")
        } catch {
            print("Error adding route to map: \(error)")
        }
    }

I used to call this method to draw my routes mapView.show(availableRoutes) but that has been depreciated after I updated. I am having trouble finding the right way to display routes on the most up to date version. Is it my code or mapbox is not working?

Screenshot 2024-05-17 at 9 00 35 PM
@petermulsh petermulsh added the bug 🪲 Something is broken! label May 18, 2024
@pjleonard37
Copy link
Contributor

Hi @petermulsh -

Thanks for sharing this report about the issues you are seeing with your implementation of the Maps and Navigation SDKs. More information is needed to identify the root cause of this issue you are seeing. To more easily share this info, please reach out to our Support team using the contact form linked at the bottom of this page. They can assist you in diagnosing the problem.

As your investigation will continue there I'm going to close out this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something is broken!
Projects
None yet
Development

No branches or pull requests

2 participants