Skip to main content

Map

The Map module returns facility markers for a given coordinate or map viewport. Use these markers to build an interactive map experience -- pins, callouts, and an "Add" flow that associates a facility with the member's account so it can be geofenced.


Data Model

MapMarker

Each marker represents a facility suitable for rendering on a map.

FieldTypeDescription
facilityIdInt?Unique facility identifier.
nameString?Display name of the facility.
latitudeDouble?Geographic latitude.
longitudeDouble?Geographic longitude.

Search Nearby

Retrieve facilities around a specific coordinate. Use this when the map first opens, centered on the member's current location.

lifecycleScope.launch {
val markers = withContext(Dispatchers.IO) {
AFCore.map().getNearbyFacilities(
latitude = memberLocation.latitude,
longitude = memberLocation.longitude
)
}
mapRenderer.showMarkers(markers.filterNotNull())
}

Search by Viewport

Retrieve facilities within the visible map region. Call this when the user pans or zooms the map.

Parameters

ParameterTypeDescription
upperLeftLatDoubleLatitude of the upper-left corner of the viewport.
upperLeftLngDoubleLongitude of the upper-left corner of the viewport.
lowerRightLatDoubleLatitude of the lower-right corner of the viewport.
lowerRightLngDoubleLongitude of the lower-right corner of the viewport.
// Called when the map camera becomes idle after a pan or zoom
fun onCameraIdle(bounds: LatLngBounds) {
lifecycleScope.launch {
val markers = withContext(Dispatchers.IO) {
AFCore.map().getFacilitiesByViewPort(
upperLeftLat = bounds.northeast.latitude,
upperLeftLng = bounds.southwest.longitude,
lowerRightLat = bounds.southwest.latitude,
lowerRightLng = bounds.northeast.longitude
)
}
mapRenderer.showMarkers(markers.filterNotNull())
}
}

Add a Facility from the Map

When the member selects a marker and confirms, add the facility to their account using the Facilities module. Once added, the facility becomes eligible for geofence monitoring.

val result = AFCore.facilities().update(facilityId = marker.facilityId, verified = true)
if (result.status) {
showSuccess("Facility added")
}

The Map module does not start geofencing by itself. Adding a facility associates it with the member; your app's geofencing flow (via startMonitoring()) handles visit detection.


Best Practices

  • Load nearby on first open, then switch to viewport. Use getNearbyFacilities when the map first appears, then call getFacilitiesByViewPort after the user pans or zooms. This reduces initial request size.
  • Debounce camera events. Map frameworks fire regionDidChange / onCameraIdle frequently during gestures. Debounce calls to avoid excessive API requests.
  • Cluster dense markers. If the server returns many facilities in a small area, use marker clustering for readability and performance.
  • Disable the "Add" button for existing facilities. Cross-reference map markers with the member's facility list to prevent duplicate additions.
  • Cache the last response. Keep the most recent marker set in memory to avoid flicker on small pan or zoom adjustments.

Quick Reference

AFCore.map().getNearbyFacilities(latitude, longitude)
AFCore.map().getFacilitiesByViewPort(upperLeftLat, upperLeftLng, lowerRightLat, lowerRightLng)
AFCore.facilities().update(facilityId, verified = true) // Add from map