Find routes from several locations to the respective closest facility.
      
  
    
Use case
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.
How to use the sample
Tap the button to solve and display the route from each incident (fire) to the nearest facility (fire station).
How it works
- Create a 
ClosestFacilityTaskusing a URL from an online service. - Get the default set of 
ClosestFacilityParametersfrom the task:closestFacilityTask.CreateDefaultParametersAsync(). - Build a list of all 
FacilitiesandIncidents:- Create a 
FeatureTableusingServiceFeatureTable(Uri). - Query the 
FeatureTablefor allFeaturesusingQueryFeaturesAsync(queryParameters). - Iterate over the result and add each 
Featureto theList, instantiating the feature as aFacilityorIncident. 
 - Create a 
 - Add a list of all facilities to the task parameters.
 - Add a list of all incidents to the task parameters.
 - Get 
ClosestFacilityResultby solving the task with the provided parameters. - Find the closest facility for each incident by iterating over the list of 
Incidents. - Display the route as a 
Graphicusing theclosestFacilityRoute.RouteGeometry. 
Relevant API
- ClosestFacilityParameters
 - ClosestFacilityResult
 - ClosestFacilityRoute
 - ClosestFacilityTask
 - Facility
 - Graphic
 - GraphicsOverlay
 - Incident
 
Tags
incident, network analysis, route, search
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.ClosestFacilityStatic.ClosestFacilityStatic"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <esriUI:MapView x:Name="MyMapView" />
        <StackLayout Grid.Row="1"
                     Margin="5,10"
                     HeightRequest="50"
                     Orientation="Horizontal">
            <Button x:Name="SolveRoutesButton"
                    Clicked="SolveRoutesClick"
                    HorizontalOptions="FillAndExpand"
                    Text="Solve Routes" />
            <Button x:Name="ResetButton"
                    Clicked="ResetClick"
                    HorizontalOptions="FillAndExpand"
                    Text="Reset" />
        </StackLayout>
    </Grid>
</ContentPage>