I've an issue that I cannot use for loop on NMACoreRouter (HereMap SDK) If i did it once time by action, it still work!. i dont know why cannot apply into loop. Funny that the error return at the second loop it "NMARoutingError" only
Here is my code
//route
var coreRouter: NMACoreRouter!
var mapRoute: NMAMapRoute?
typealias RouteContainer = (plan: [NMAGeoCoordinates], mode: NMARoutingMode)
for var shop in pickedShopData {
self.calculateRouteLength(startLat: self.curentUserGeo.latitude, startLong: self.curentUserGeo.longitude, endLat: shop.shopLat, endLong: shop.shopLong)
}
func calculateRouteLength(startLat: Double, startLong: Double, endLat: Double, endLong: Double) {
coreRouter = NMACoreRouter()
/* Define waypoints for the route */
let startPoint = NMAGeoCoordinates(latitude: startLat, longitude: startLong)
let endPoint = NMAGeoCoordinates(latitude: endLat, longitude: endLong)
/* Initialize a RoutePlan */
let routePlan = [startPoint, endPoint]
/*
* Initialize a RouteOption. HERE Mobile SDK allows users to define their own parameters for the
* route calculation,including transport modes,route types and route restrictions etc.Please
* refer to API doc for full list of APIs
*/
let routeMode = NMARoutingMode()
/* Other transport modes are also available e.g Pedestrian */
routeMode.transportMode = NMATransportMode.scooter
/* Disable highway in this route. */
routeMode.routingOptions.insert(NMARoutingOption.avoidHighway)
/* Calculate the shortest route available. */
routeMode.routingType = NMARoutingType.fastest
/* Calculate 1 route. */
routeMode.resultLimit = 3
coreRouter.calculateRoute(withStops: routePlan, routingMode: routeMode,
{ [self] (result, error) in
// check error and unwrap route
guard let route = result?.routes?.first, error == NMARoutingError.none else {
print("error \(error)")
return
}
// check if map object already exist
if let tempMapRoute = self.mapRoute {
self.mapView?.remove(mapObject: tempMapRoute)
}
// create map object from route
guard let mapRoute = NMAMapRoute(route) else {
return
}
print("distance \(mapRoute.route.length)")
})
}