chore(Snippets): Add Maps Compose snippets. (#841)

Change-Id: Idd9903a3570a1427491dd98442bffcfd985f11bf
This commit is contained in:
Chris Arriola 2022-02-07 13:37:16 -08:00 committed by GitHub
parent 916fcad76a
commit 96daebca63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 2 deletions

View File

@ -7,12 +7,12 @@ plugins {
}
android {
compileSdkVersion 31
compileSdkVersion 32
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.google.maps.example"
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@ -25,6 +25,14 @@ android {
}
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0-alpha02'
}
buildFeatures {
compose true
}
flavorDimensions "version"
productFlavors {
@ -50,6 +58,8 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.compose.foundation:foundation:1.2.0-alpha02"
implementation "androidx.compose.material:material:1.2.0-alpha02"
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment:2.4.0'
@ -58,6 +68,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
gmsImplementation 'com.google.maps.android:maps-ktx:3.3.0'
gmsImplementation 'com.google.maps.android:maps-compose:1.0.0'
gmsImplementation 'com.google.android.gms:play-services-maps:18.0.2'
gmsImplementation 'com.google.maps.android:android-maps-utils:2.3.0'
v3Implementation 'com.google.android.libraries.maps:maps:3.1.0-beta'

View File

@ -0,0 +1,63 @@
package com.google.maps.example.kotlin
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Switch
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.compose.GoogleMap
import com.google.maps.android.compose.MapProperties
import com.google.maps.android.compose.MapType
import com.google.maps.android.compose.MapUiSettings
import com.google.maps.android.compose.Marker
import java.util.Properties
@Composable
fun AddAMap() {
// [START maps_android_compose_add_a_map]
val singapore = LatLng(1.35, 103.87)
GoogleMap(
modifier = Modifier.fillMaxSize(),
googleMapOptionsFactory = {
GoogleMapOptions().camera(CameraPosition.fromLatLngZoom(singapore, 11f))
}
) {
Marker(
position = singapore,
title = "Singapore",
snippet = "Marker in Singapore"
)
}
// [END maps_android_compose_add_a_map]
}
@Composable
fun Properties() {
// [START maps_android_compose_set_properties]
var uiSettings by remember { mutableStateOf(MapUiSettings()) }
var properties by remember {
mutableStateOf(MapProperties(mapType = MapType.SATELLITE))
}
Box(Modifier.fillMaxSize()) {
GoogleMap(
modifier = Modifier.matchParentSize(),
properties = properties,
uiSettings = uiSettings
)
Switch(
checked = uiSettings.zoomControlsEnabled,
onCheckedChange = {
uiSettings = uiSettings.copy(zoomControlsEnabled = it)
}
)
}
// [END maps_android_compose_set_properties]
}