ArcGIS Runtime Error Occurred. Set a breakpoint on C++ exceptions to see the original callstack and context for this error: Error Domain=com.esri.arcgis.runtime.error Code=15 "Invalid call."
My code:
public func startRoute(to destination: AGSPoint) {
queue.async { [weak self] in
guard let self = self else {
Logger.log(error: nil)
return
}
// set destination and start locations
self.destinationLocation = destination
self.startLocation = AGSPoint(clLocationCoordinate2D: self.positionManager.current.toCLLocation().coordinate)
self.routeTask = AGSRouteTask(databaseName: "", networkName: "")
self.routeTask.defaultRouteParameters { [weak self] (params: AGSRouteParameters?, error: Error?) in
guard let self = self else {
Logger.log(error: nil)
return
}
if let params = params {
params.returnDirections = true
params.returnStops = true
params.returnRoutes = true
params.outputSpatialReference = .wgs84()
params.setStops(self.makeStops())
self.routeParameters = params
// calculate route
self.routeTask.solveRoute(with: params) { [weak self] result, error in
guard let self = self else { return }
if let result = result {
// success
self.didSolveRoute(with: .success(result))
} else if let error = error {
// failure
self.didSolveRoute(with: .failure(error))
}
}
} else if let error = error {
guard let del = self.delegateelse { return }
del.updateNavigationView(direction: "Error \((error as NSError).code)", directions: [AGSDirectionManeuver]())
Logger.routing.error("Failed to get route parameters with error \(error.localizedDescription, privacy: .public)")
}
}
}
}
func startEsriNavigation(to point: AGSPoint) {
guard let positionManager = positionManagerelse {
return
}
routeService = RMRouteService(positionManager: positionManager)
routeService.delegate = self
routeService.startRoute(to: point)
mapToolsView.navigationPoint = point
isRouting = true
self.toggleMapTools(toolIndex: 1)
DispatchQueue.main.async { [weak self] in
self?.esriMap.locationDisplay.start()
self?.navigationButton.isHidden = false
}
}
Hi Carlos,
Can you provide a minimum reproducible example for your error? Also, you may take a look at the example code for navigation in the samples app.
From the code you provide, I can see some issues that might contribute to an error, though am not sure which is yours
- The route task is created with an invalid database
- The result of route solving is not used
- No license key or API key is explicitly set to use the routing functionalities
I removed the database and network names. Not sure if it's sensitive information or not. That data is valid.
I looked at your example, how should I use didSolveRoute?
Can you send some examples on how and where to set the license or api key?
is it different from the esri sdk license that I set on application start up?
If you have set a global key on the AGSArcGISRuntimeEnvironment, then you should be good.
didSolveRoute in that sample is just a helper method to handle the AGSRouteResult. From there you can create an AGSRouteTracker with the result, and then have the location display (blue dot) to snap to the route. I would encourage you to download the samples app and run it locally, play with it a bit and set breakpoints at where your error happens to see what is the cause.
There is another guide on the developer website that breaks down each step to configure the route tracker.
Can you let me know which line in your code gives the error? A minimum repro app would be the best. You can also first try with Esri's World Route API in the AGSRouteTask to ensure it is not a data problem.
Thank you for the documentation.
When I add break points it doesn't hit
if let params.
Im not sure, I'm receiving an error code 24. Object is already owned
There are too much going on in your code, thus it is hard to tell the real problem. Try to strip down anything unrelated first. I'd suggest starting clean from sth like this
import UIKit
import ArcGIS
class ViewController: UIViewController {
@IBOutlet var mapView: AGSMapView! {
didSet {
let map = AGSMap(basemapStyle: .arcGISLightGray)
mapView.map = map
}
}
let stops: [AGSStop] = {
let stop1 = AGSStop(point: AGSPoint(x: -117.160386727, y: 32.706608, spatialReference: .wgs84()))
stop1.name = "San Diego Convention Center"
let stop2 = AGSStop(point: AGSPoint(x: -117.173034, y: 32.712329, spatialReference: .wgs84()))
stop2.name = "USS San Diego Memorial"
let stop3 = AGSStop(point: AGSPoint(x: -117.147230, y: 32.730467, spatialReference: .wgs84()))
stop3.name = "RH Fleet Aerospace Museum"
return [stop1, stop2, stop3]
}()
/// The route task to solve the route between stops, using the online routing service.
let routeTask = AGSRouteTask(url: URL(string: "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World")!)
func solveRoute(routeTask: AGSRouteTask) {
routeTask.defaultRouteParameters { [weak self] (params: AGSRouteParameters?, error: Error?) in
guard let self = self else { return }
if let params = params {
// Explicitly set values for parameters.
params.returnDirections = true
params.returnStops = true
params.returnRoutes = true
params.outputSpatialReference = .wgs84()
params.setStops(self.stops)
self.routeTask.solveRoute(with: params) { (result: AGSRouteResult?, error: Error?) in
if let result = result {
print(result.routes.first!.directionManeuvers.map(\.directionText).joined(separator: "\n"))
} else if let error = error {
print(error.localizedDescription)
}
}
} else if let error = error {
print(error.localizedDescription)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
solveRoute(routeTask: routeTask)
}
}
The workflow is pretty intuitive:
1. Create a route task. Either from a network database or from the Esri online route service.
2. Create the route parameters. If succeeds, the closure will call back the routing parameters.
3. Solve the route with the parameters. The closure will call back a route result or an error.
Again, it would be great if you can create a minimal repro case based on the snippet above. It will help us to find the issue. 🙂