Find routes from several locations to the respective closest facility.
Quickly and accurately determining the most efficient route between a location and a facility is a frequently encountered task. For example, a city's fire department may need to know which fire stations in the vicinity offer the quickest routes to multiple fires. Solving for the closest fire station to the fire's location using an impedance of "travel time" would provide this information.
Tap the button to solve and display the route from each incident (fire) to the nearest facility (fire station).
- Create a
ClosestFacilityTask
using a URL from an online service. - Get the default set of
ClosestFacilityParameters
from the task:closestFacilityTask.CreateDefaultParametersAsync()
. - Build a list of all
Facilities
andIncidents
:- Create a
FeatureTable
usingServiceFeatureTable(Uri)
. - Query the
FeatureTable
for allFeatures
usingQueryFeaturesAsync(queryParameters)
. - Iterate over the result and add each
Feature
to theList
, instantiating the feature as aFacility
orIncident
.
- Create a
- Add a list of all facilities to the task parameters.
- Add a list of all incidents to the task parameters.
- Get
ClosestFacilityResult
by solving the task with the provided parameters. - Find the closest facility for each incident by iterating over the list of
Incident
s. - Display the route as a
Graphic
using theclosestFacilityRoute.RouteGeometry
.
- ClosestFacilityParameters
- ClosestFacilityResult
- ClosestFacilityRoute
- ClosestFacilityTask
- Facility
- Graphic
- GraphicsOverlay
- Incident
incident, network analysis, route, search