Find a route to the closest facility from a location.

Use case
Quickly and accurately determining the most efficient route between a location and a facility is a frequently encountered task. For example, a paramedic may need to know which hospital in the vicinity offers the possibility of getting an ambulance patient critical medical care in the shortest amount of time. Solving for the closest hospital to the ambulance’s location using an impedance of “travel time” would provide this information.
How to use the sample
Tap near any of the hospitals and a route will be displayed from that tapped location to the nearest hospital.
How it works
- Create a
ClosestFacilityTaskusing a URL from an online network analysis service. - Get
ClosestFacilityParametersfrom the task,ClosestFacilityTask.makeDefaultParameters(). - Add facilities to the parameters,
ClosestFacilityParameters.setFacilities(_:). - Add an incident to the parameters,
ClosestFacilityParameters.setIncidents(_:). - Get a
ClosestFacilityResultby solving task with parameters,ClosestFacilityTask.solveClosestFacility(using:). - Get the index list of closest facilities to the incident,
ClosestFacilityResult.rankedIndexesOfFacilities(forIncidentAtIndex:). - Get the index of closest facility.
- Find the closest facility route,
ClosestFacilityResult.route(toFacilityAtIndex:fromIncidentAtIndex:). - Display the route on the
MapViewas aGraphicon aGraphicsOverlay.
Relevant API
- ClosestFacilityParameters
- ClosestFacilityResult
- ClosestFacilityRoute
- ClosestFacilityTask
- Facility
- Graphic
- GraphicsOverlay
- Incident
- MapView
Tags
incident, network analysis, route, search