Add Marker (Android)
Place markers on the map to highlight specific locations.
MapSession required
Remember to integrate the MapSession in your app. The MapSession must be called periodically every 10 minutes while the map is active.
Single Marker
mapView.getMapAsync { map ->
map.setStyle(
"https://tiles.smartmaps.cloud/styles/v1/smartmaps/light/style.json?apiKey=[INSERT API-KEY]&channel=app"
) { style ->
map.addMarker(
MarkerOptions()
.position(LatLng(49.0069, 8.4037))
.title("Karlsruhe")
.snippet("SmartMaps Headquarters")
)
map.cameraPosition = CameraPosition.Builder()
.target(LatLng(49.0069, 8.4037))
.zoom(12.0)
.build()
}
}
Multiple Markers
mapView.getMapAsync { map ->
map.setStyle(
"https://tiles.smartmaps.cloud/styles/v1/smartmaps/light/style.json?apiKey=[INSERT API-KEY]&channel=app"
) { style ->
val locations = listOf(
Triple(LatLng(49.0069, 8.4037), "Karlsruhe", "Baden-Wuerttemberg"),
Triple(LatLng(48.7758, 9.1829), "Stuttgart", "State Capital"),
Triple(LatLng(49.4875, 8.4660), "Mannheim", "Rhine-Neckar Region"),
Triple(LatLng(48.3705, 10.8978), "Augsburg", "Bavaria")
)
locations.forEach { (position, title, snippet) ->
map.addMarker(
MarkerOptions()
.position(position)
.title(title)
.snippet(snippet)
)
}
// Fit camera to show all markers
val bounds = LatLngBounds.Builder()
.includes(locations.map { it.first })
.build()
map.easeCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50))
}
}
Custom Marker Icon
mapView.getMapAsync { map ->
map.setStyle(
"https://tiles.smartmaps.cloud/styles/v1/smartmaps/light/style.json?apiKey=[INSERT API-KEY]&channel=app"
) { style ->
val icon = IconFactory.getInstance(this)
.fromResource(R.drawable.custom_marker)
map.addMarker(
MarkerOptions()
.position(LatLng(49.0069, 8.4037))
.title("Custom Marker")
.icon(icon)
)
}
}