Map

The map component provides an interactive interface to display geographical data, supporting features such as zoom, markers and more maps settings. It allows users to navigate and explore locations, and interact with map elements like marker, shape, etc.

TypeResource
DesignFigma
MobileMobile Storybook
CodeGitlab

Stepper Preview

Pre-Usage

Ensure your project meets the following requirements:

Open your module-level build.gradle.kts file and add the following code to the plugins element.

plugins {
    // ...
    id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

Open the .properties file in your top-level directory, and then add the following code. Replace YOUR_API_KEY with your API key

MAPS_API_KEY=YOUR_API_KEY

In your AndroidManifest.xml file, go to com.google.android.geo.API_KEY and update the android:value attribute. If the <meta-data> tag doesn’t exist, create it as a child of the <application> tag.

Usage

To implement Map, you can use this tag Maps in the Kotlin file. This component is build using android-map-compose package.

    import id.co.biofarma.binduiandroid.components.maps.Maps
    import id.co.biofarma.binduiandroid.model.CircleProperties
    import id.co.biofarma.binduiandroid.model.MapConfig
    import id.co.biofarma.binduiandroid.model.MarkerProperties
    import id.co.biofarma.binduiandroid.model.PolygonProperties
    import id.co.biofarma.binduiandroid.model.PolylineProperties
    import id.co.biofarma.binduiandroid.model.enums.MarkerType
    import com.google.android.gms.maps.GoogleMap
        mapConfig = MapConfig()
        markers = listOf( MarkerProperties() )
        polylines = listOf( PolylineProperties() )
        polygons = listOf( PolygonProperties() )
        circles = listOf( CircleProperties() )
 
        
        fun mapEffects(map: GoogleMap) {
            // example listener
            map.setOnMapClickListener {}
            map.setOnMapLongClickListener() {}
        }
 
        Maps(
            config = mapConfig,
            modifier = Modifier
                .fillMaxSize(),
            markers = markers,
            polylines = polylines,
            polygons = polygons,
            circles = circles,
            mapEffect = { googleMap -> mapEffects(googleMap) }
        )

Map with markers

Adding the list of MarkerProperties() into the Maps markers parameter

Markers


Data Class

Since the Maps component is built using the android-map-compose package, it fully supports the use of the Map class, including MapProperties, MapUiSettings, and the functionality provided by the MapEffect class. It also fully supports the Marker, Polyline, Polygon, and Circle composables with their complete set of properties.

MapConfig
data class MapConfig(
    val mapId: String = "",
    val defaultLocation: LatLng = LatLng(-6.174505, 106.826717),
    val defaultZoom: Float = 10f,
    val mapProperties: MapProperties = MapProperties(),
    val mapUiSettings: MapUiSettings = MapUiSettings(),
)
PropertiesRequiredDefaultTypedescription
mapIdfalse""StringThe map id identifier
defaultLocationfalseLatLng(-6.174505, 106.826717) jakartaLatLngLatLng class from com.google.android.gms.maps.model package
defaultZoomfalse10fFloatthe Map default zoom
mapPropertiesfalseMapPropertiesMapPropertiesMapProperties class from com.google.android.gms.maps.model
mapUiSettingsfalseMapUiSettingsMapUiSettingsMapUiSettings class from com.google.android.gms.maps.model
Marker
MarkerType

The enum class of the MarkerType

Type
PRIMARY
SECONDARY
INFO
SUCCESS
DANGER
WARNING

Determine the style of the marker to be displayed: Marker Type Preview

MarkerProperties

A properties of a composable marker on the map.

data class MarkerProperties(
    val coordinates: LatLng,
    val radius: Double? = null,
    val type: MarkerType = MarkerType.PRIMARY,
    val alpha: Float = 1.0f,
    val anchor: Offset = Offset(0.5f, 1.0f),
    val draggable: Boolean = false,
    val flat: Boolean = false,
    val icon: BitmapDescriptor? = null,
    val infoWindowAnchor: Offset = Offset(0.5f, 0.0f),
    val rotation: Float = 0.0f,
    val snippet: String? = null,
    val tag: Any? = null,
    val title: String? = null,
    val visible: Boolean = true,
    val zIndex: Float = 0.0f,
    val onClick: (Marker) -> Boolean = { false },
    val onInfoWindowClick: (Marker) -> Unit = {},
    val onInfoWindowClose: (Marker) -> Unit = {},
    val onInfoWindowLongClick: (Marker) -> Unit = {},
    val isShowTooltip: Boolean = false,
    val isEnableCustomTooltip:  Boolean = false,
    val tooltipContent: @Composable () -> Unit = {},
)
Propsdescription
coordinatesthe LatLng for the marker locaation
radiusthe marker radius
typeMarkerType enum class
alphathe alpha (opacity) of the marker
anchorthe anchor for the marker image
draggablesets the draggability for the marker
flatsets if the marker should be flat against the map
iconsets the icon for the marker
infoWindowAnchorthe anchor point of the info window on the marker image
rotationthe rotation of the marker in degrees clockwise about the marker’s anchor point
snippetthe snippet for the marker
tagoptional tag to associate with the marker
titlethe title for the marker
visiblethe visibility of the marker
onClicka lambda invoked when the marker is clicked
onInfoWindowClicka lambda invoked when the marker’s info window is clicked
onInfoWindowClosea lambda invoked when the marker’s info window is closed
onInfoWindowLongClicka lambda invoked when the marker’s info window is long clicked
PolylineProperties

A properties of a composable polyline on the map.

data class PolylineProperties(
    val points: List<LatLng>,
    val clickable: Boolean = false,
    val color: Color = Color.Black,
    val endCap: Cap = ButtCap(),
    val geodesic: Boolean = false,
    val jointType: Int = JointType.DEFAULT,
    val pattern: List<PatternItem>? = null,
    val startCap: Cap = ButtCap(),
    val tag: Any? = null,
    val visible: Boolean = true,
    val width: Float = 10f,
    val zIndex: Float = 0f,
    val onClick: (Polyline) -> Unit = {}
)
Propsdescription
pointsthe points comprising the polyline
clickableboolean indicating if the polyline is clickable or not
colorthe color of the polyline
endCapa cap at the end vertex of the polyline
geodesicspecifies whether to draw the polyline as a geodesic
jointTypethe joint type for all vertices of the polyline except the start and end vertices
patternthe pattern for the polyline
startCapthe cap at the start vertex of the polyline
visiblethe visibility of the polyline
visiblethe visibility of the polyline
widththe width of the polyline in screen pixels
zIndexthe z-index of the polyline
onClicka lambda invoked when the polyline is clicked
PolygonProperties

A properties of a composable polygon on the map.

data class PolygonProperties(
    val points: List<LatLng>,
    val clickable: Boolean = false,
    val fillColor: Color = Color.Black,
    val geodesic: Boolean = false,
    val holes: List<List<LatLng>> = emptyList(),
    val strokeColor: Color = Color.Black,
    val strokeJointType: Int = JointType.DEFAULT,
    val strokePattern: List<PatternItem>? = null,
    val strokeWidth: Float = 10f,
    val tag: Any? = null,
    val visible: Boolean = true,
    val zIndex: Float = 0f,
    val onClick: (Polygon) -> Unit = {}
)
Propsdescription
pointsthe points comprising the vertices of the polygon
clickableboolean indicating if the polygon is clickable or not
fillColorthe fill color of the polygon
geodesicspecifies whether to draw each segment as a geodesic
holesthe holes for the polygon
strokeColorthe stroke color of the polygon
strokeJointTypethe joint type for all vertices of the polygon’s outline
strokePatternthe stroke pattern for the polygon’s outline
strokeWidthspecifies the polygon’s stroke width, in display pixels
tagoptional tag to associate wiht the polygon
visiblethe visibility of the polygon
zIndexthe z-index of the polygon
onClicka lambda invoked when the polygon is clicked
CircleProperties

A properties of a composable circle on the map.

data class CircleProperties(
    val center: LatLng,
    val clickable: Boolean = false,
    val fillColor: Color = Color.Black,
    val radius: Double = 10.0,
    val strokeColor: Color = Color.Black,
    val strokePattern: List<PatternItem>? = null,
    val strokeWidth: Float = 10f,
    val tag: Any? = null,
    val visible: Boolean = true,
    val zIndex: Float = 0f,
    val onClick: (Circle) -> Unit = {},
)
Propsdescription
centerthe LatLng to use for the center of this circle
clickableboolean indicating if the circle is clickable or not
fillColorthe fill color of the circle
radiusthe radius of the circle in meters.
strokeColorthe stroke color of the circle
strokePatterna sequence of PatternItem to be repeated along the circle’s outline (null represents a solid line)
tagoptional tag to be associated with the circle
strokeWidththe width of the circle’s outline in screen pixels
visiblethe visibility of the circle
zIndexthe z-index of the circle
onClicka lambda invoked when the circle is clicked

Maps Props

PropsRequiredDefaultTypedescription
configtrueMapConfigThe configuration object of the Maps e.g defaultLocation, mapProperties, and mapUiSettings
modifierfalseModifierModifierModifer for the maps container
markersfalseList<>List<MarkerProperties>The markers to be displayed inside the map
polylinesfalseList<>List<PolylineProperties>The polyline shapes to be displayed on the map.
polygonsfalseList<>List<PolygonProperties>The polygon shapes to be displayed on the map.
circlesfalseList<>List<CircleProperties>The circle shapes to be displayed on the map.
mapEffectfalseGoogleMapGoogleMapA callback function to apply custom map effects. The function receives GoogleMap object from com.google.android.gms.maps.GoogleMap as a parameter
BIND © Biofarma Innovate Next-level Design .