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

func addPolyline don't work #2

Open
timur-gaysin opened this issue May 22, 2023 · 4 comments
Open

func addPolyline don't work #2

timur-gaysin opened this issue May 22, 2023 · 4 comments

Comments

@timur-gaysin
Copy link

I'm trying to add routes in your library. But after call this code:

let mapObjects = mapViewLocal.mapWindow.map.mapObjects
for route in routes {
      mapObjects.addPolyline(with: route.geometry)
}

nothing happens. What's wrong?

@aramayyes
Copy link
Owner

Hello, @timur-gaysin.

This library doesn't support routes yet. Where do you add that code?

@timur-gaysin
Copy link
Author

i am add this code in YandexMapView in public func onMapObjectTap(...

@aramayyes
Copy link
Owner

Can you please send the whole code for investigation?

@timur-gaysin
Copy link
Author

public func onMapObjectTap(
      with mapObject: YMKMapObject,
      point _: YMKPoint
    ) -> Bool {
        print("onMapObjectTap")
      if let placemarkObject = mapObject as? YMKPlacemarkMapObject,
         let placemark = placemarkObject.userData as? Placemark
      {
          
          let ROUTE_START_POINT = YMKPoint(latitude:10.00, longitude: 10.00)

          let ROUTE_END_POINT = YMKPoint(latitude: placemark.location.latitude, longitude: placemark.location.longitude)

          let requestPoints : [YMKRequestPoint] = [
                      YMKRequestPoint(point: ROUTE_START_POINT, type: .waypoint, pointContext: nil),
                      YMKRequestPoint(point: ROUTE_END_POINT, type: .waypoint, pointContext: nil),
                      ]
          DispatchQueue.main.async { [self] in
              createRoute(requestPoints: requestPoints)
          }
        return view.placemarkTapAction(placemark)
      }

      return false
    }
      
      func createRoute(requestPoints : [YMKRequestPoint]){
          let CAMERA_TARGET = YMKPoint(latitude: requestPoints[0].point.latitude, longitude: requestPoints[0].point.longitude)
          self.view.mapViewLocal.mapWindow.map.move(
              with: YMKCameraPosition(target: CAMERA_TARGET, zoom: 6, azimuth: 0, tilt: 0))
          
          let responseHandler = {(routesResponse: [YMKDrivingRoute]?, error: Error?) -> Void in
              if let routes = routesResponse {
                  self.onRoutesReceived(routes)
              } else {
                  self.onRoutesError(error!)
              }
          }
                  
          let drivingRouter = YMKDirections.sharedInstance().createDrivingRouter()
          drivingSession = drivingRouter.requestRoutes(
              with: requestPoints,
              drivingOptions: YMKDrivingDrivingOptions(),
              vehicleOptions: YMKDrivingVehicleOptions(),
              routeHandler: responseHandler)
      }
      
      func onRoutesReceived(_ routes: [YMKDrivingRoute]) {
          let mapObjects = self.view.mapViewLocal.mapWindow.map.mapObjects
          for route in routes {
              mapObjects.addPolyline(with: route.geometry)
          }
      }

In debug mode - mapObjects.addPolyline(with: route.geometry) called, but nothing drawing on map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants