Find closest facility to an incident (interactive)

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Find a route to the closest facility from a location.

Image of find closest facility to an incident interactive

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

  1. Create a ClosestFacilityTask using a Url from an online network analysis service.
  2. Get ClosestFacilityParameters from task, task.CreateDefaultParametersAsync()
  3. Add facilities to parameters, closestFacilityParameters.Facilities.AddAll(facilities).
  4. Add the incident to parameters, closestFacilityParametersIncidents.
  5. Get ClosestFacilityResult from solving task with parameters, task.SolveClosestFacilityAsync(facilityParameters)
  6. Get index list of closet facilities to incident, facilityResult.RankedFacilities[0]
  7. Get index of closest facility, rankedFacilitiesList[0]
  8. Find closest facility route, facilityResult.Route(closestFacilityIndex, IncidentIndex)
  9. Display route to MapView:
    • Create Graphic from route geometry, new Graphic(route.RouteGeometry)
    • Add graphic to GraphicsOverlay which is attached to the mapview

Relevant API

  • ClosestFacilityParameters
  • ClosestFacilityResult
  • ClosestFacilityRoute
  • ClosestFacilityTask
  • Facility
  • Graphic
  • GraphicsOverlay
  • Incident
  • MapView

Tags

incident, network analysis, route, search

Sample Code

ClosestFacility.xamlClosestFacility.xamlClosestFacility.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.ClosestFacility.ClosestFacility"
             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>
        <esriUI:MapView x:Name="MyMapView" />
    </Grid>
</ContentPage>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.