Find the service areas of several facilities from a feature service.

Use case
A city taxi company may calculate service areas around their vehicle lots to identify gaps in coverage. Alternatively, they may want to ensure overlaps where a high volume of passengers requires redundant facilities, such as near an airport.
How to use the sample
Upon running, the sample will calculate and display the service area of each facility (hospital) on the map. The polygons displayed around each facility represents the facility’s service area: the red area is within 1 minute travel time from the hospital by car, whilst orange is within 3 minutes by car. All service areas are semi-transparent to show where they overlap.
How it works
- Create a new
ServiceAreaTaskfrom a network service. - Create default
ServiceAreaParametersfrom the service area task. - Set the parameters
returnsPolygonsproperty totrueto return polygons of all service areas. - Define
QueryParametersthat retrieve all features from the facilitiesFeatureTable. Add the facilities to the service area parameters using the query parameters,serviceAreaParameters.setFacilities(fromFeaturesIn:queryParameters:) - Get the
ServiceAreaResultby solving the service area task using the parameters. - For each facility, get any
ServiceAreaPolygonsthat were returned,ServiceAreaResult.resultPolygons(forFacilityAtIndex:). - Display each service area polygon as a
Graphicin aGraphicsOverlayon theMapView.
Relevant API
- ServiceAreaParameters
- ServiceAreaPolygon
- ServiceAreaResult
- ServiceAreaTask
About the data
This sample uses a street map of San Diego, in combination with a feature service with facilities (used here to represent hospitals). Additionally a street network is used on the server for calculating the service area.
Tags
facilities, feature service, impedance, network analysis, service area, travel time