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
Click near any of the hospitals and a route will be displayed from that clicked location to the nearest hospital.
How it works
- Create a
ClosestFacilityTask
using a Url from an online network analysis service. - Get
ClosestFacilityParameters
from task,task.CreateDefaultParametersAsync()
- Add facilities to parameters,
closestFacilityParameters.Facilities.AddAll(facilities)
. - Add the incident to parameters,
closestFacilityParametersIncidents
. - Get
ClosestFacilityResult
from solving task with parameters,task.SolveClosestFacilityAsync(facilityParameters)
- Get index list of closet facilities to incident,
facilityResult.RankedFacilities[0]
- Get index of closest facility,
rankedFacilitiesList[0]
- Find closest facility route,
facilityResult.Route(closestFacilityIndex, IncidentIndex)
- Display route to
MapView
:- Create
Graphic
from route geometry,new Graphic(route.RouteGeometry)
- Add graphic to
GraphicsOverlay
which is attached to the mapview
- Create
Relevant API
- ClosestFacilityParameters
- ClosestFacilityResult
- ClosestFacilityRoute
- ClosestFacilityTask
- Facility
- Graphic
- GraphicsOverlay
- Incident
- MapView
Tags
incident, network analysis, route, search
Sample Code
<UserControl x:Class="ArcGIS.UWP.Samples.ClosestFacility.ClosestFacility"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esri:MapView x:Name="MyMapView" />
<Border Style="{StaticResource BorderStyle}">
<TextBlock Text="Tap to find the route to the closest facility."
TextAlignment="Center" FontWeight="SemiBold" />
</Border>
</Grid>
</UserControl>