Route Preview
When you show a route to the user before navigation begins, the SDK draws a route-preview on the map. In 26.7.1 you can add customizable From / To labels to the preview, and you can compute a route's distance and time without drawing it — useful for showing an estimate in a list or confirmation screen.
Availability
New in iOS SDK 26.7.1. The From/To label API is on MapstedMapUiViewController (import MapstedMapUi); the distance-only routing API is on CoreApi.RoutingManager (import MapstedCore).
From / To labels on the preview
Call enableFromToLabelsOnRoutePreview(enable:fromLabel:toLabel:) before the route preview is shown. The label text is optional — leave a label empty to use the default ("From" / "To").
import MapstedMapUi
// MapstedMapUiViewController.shared is typed as UIViewController?, so cast it
// to the concrete type — the same pattern the SDK's own template uses.
guard let mapVC = MapstedMapUiViewController.shared as? MapstedMapUiViewController else { return }
mapVC.enableFromToLabelsOnRoutePreview(enable: true, fromLabel: "Start", toLabel: "Destination")
// Use the defaults ("From" / "To"):
mapVC.enableFromToLabelsOnRoutePreview(enable: true)
// Turn the labels off:
mapVC.enableFromToLabelsOnRoutePreview(enable: false)
Android: the From/To preview labels are managed by the prebuilt UI; there is no separate client API for them in 26.7.1.
The labels apply to the next route preview the SDK draws, so set them before you trigger the preview.
Routed distance and time without drawing
requestRouteForDistance(request:completion:) computes a route only to obtain its distance and time — it does not draw the route or notify your navigation listeners. Pass an MNRouteRequest (the same request type you use elsewhere for routing) and read the result from the returned MNRouteResponse:
import com.mapsted.positioning.CoreApi;
import com.mapsted.positioning.routing.RoutingOptions;
import com.mapsted.positioning.routing.DistanceTime;
import com.mapsted.core.engine.MercatorZone;
// Distance/time to a destination without drawing a route.
DistanceTime dt = coreApi.routing()
.getDistanceTimeEstimate(destinationZone, RoutingOptions.defaultInstance());
float meters = dt.getDistanceMeters();
float km = dt.getDistanceKilometers();
float minutes = dt.getTimeMinutes();
import MapstedCore
/// Compute a route's distance and time without drawing it on the map.
func routedDistance(for request: MNRouteRequest,
completion: @escaping (_ meters: Float?, _ seconds: Float?) -> Void) {
CoreApi.RoutingManager.requestRouteForDistance(request: request) { response in
// `response` is nil only if the engine is being torn down.
guard let response = response,
let route = response.routes.first,
let distanceTime = route.bestValidRoute?.distanceTime else {
completion(nil, nil)
return
}
completion(distanceTime.distanceMeters, distanceTime.timeSeconds)
}
}
MNDistanceTime exposes the value in several units — distanceMeters, distanceKilometers, distanceFeet, distanceMiles, and timeSeconds, timeMinutes, timeHours — so you can format it to suit your UI.
Handling failures
Inspect response.routes.first?.routeError (an MNRouteError) if bestValidRoute is nil. MNRouteError carries errorType, errorTypeDescription, and an optional errorMessage.
Tips & Considerations
MapstedMapUiViewController.sharedis typedUIViewController?. Cast it withas? MapstedMapUiViewControllerbefore calling the label API (shown above).- Set the labels before the preview is drawn — the flag is read when the preview is built.
requestRouteForDistancedoes not draw anything. It is a measurement call; to actually show the route, use your normal routing/preview flow.- The completion may deliver
nilwhen the positioning engine is being torn down (for example during teardown of the map screen) — always handle it.