View on GitHub Sample viewer app

Find the service area within a network from a given point.

Image of show service area

Use case

A service area shows locations that can be reached from a facility based on a certain impedance, such as travel time or distance. Barriers can increase impedance by either adding to the time it takes to pass through the barrier or by altogether preventing passage.

For example, you might calculate the region around a hospital in which ambulances can service in 30 minutes or less.

How to use the sample

  • To add a facility, select the “Facilities” mode and tap anywhere on the map.
  • To add a barrier, select the “Barriers” mode and tap on the map to add barrier polygons.
  • Use the “Set time breaks” button to adjust the time break values for the service area calculation.
  • Tap the “Solve Service Area” button to calculate and display the service area polygons around the facilities, considering any barriers.
  • Use the “Clear” button to remove all facilities, barriers, and service area polygons from the map.

How it works

  1. Create a ServiceAreaTask from a network analysis service.
  2. Create default ServiceAreaParameters from the service area task.
  3. Set the parameters to return polygons and dissolve overlapping areas.
  4. Add one or more ServiceAreaFacility instances at the locations of the facility graphics.
  5. Add any polygon barriers as PolygonBarrier instances.
  6. Set the time breaks (impedance cutoffs) for the service area calculation.
  7. Solve the service area task using the parameters to get a ServiceAreaResult.
  8. Get any ServiceAreaPolygon results and display them as graphics in a GraphicsOverlay on the map.

Relevant API

  • PolygonBarrier
  • ServiceAreaFacility
  • ServiceAreaParameters
  • ServiceAreaPolygon
  • ServiceAreaResult
  • ServiceAreaTask

Tags

barriers, facilities, impedance, logistics, network analysis, routing, service area

Sample Code

MainActivity.kt MainActivity.kt ShowServiceAreaViewModel.kt ShowServiceAreaScreen.kt
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.showservicearea
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.showservicearea.screens.ShowServiceAreaScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
ArcGISEnvironment.applicationContext = this
enableEdgeToEdge()
setContent {
SampleAppTheme {
ShowServiceAreaApp()
}
}
}
@Composable
private fun ShowServiceAreaApp() {
Surface(color = MaterialTheme.colorScheme.background) {
ShowServiceAreaScreen(
sampleName = getString(R.string.show_service_area_app_name)
)
}
}
}