Zum Inhalt

Add Marker (Android)

Platzieren Sie Marker auf der Karte, um bestimmte Orte hervorzuheben.

MapSession erforderlich

Denken Sie daran, die MapSession in Ihre App zu integrieren. Die MapSession muss alle 10 Minuten aufgerufen werden, solange die Karte aktiv ist.

Einzelner 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()
    }
}

Mehrere Marker

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))
    }
}

Benutzerdefiniertes Marker-Symbol

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)
        )
    }
}