这两个 Google 地图 api 标记有什么区别?

问题描述 投票:0回答:1

我有两个不同的应用程序在 android studio 中使用谷歌地图 api。一个标记要求一个状态,另一个要求一个位置。我无法将其中一个更改为另一个,因为这会导致错误。两者有什么区别? 第一个应用程序

GoogleMap(
        modifier = Modifier
            .fillMaxWidth(0.75F)
            .fillMaxHeight(0.75F),
        cameraPositionState = cameraPositionState
    ) {
        Marker(position = latLng)
        //Marker(state = MarkerState(position = latLng))   <-----This gives an error
        }

还有另一个

GoogleMap(
        modifier = Modifier
            .fillMaxWidth(0.75F)
            .fillMaxHeight(0.75F),
        cameraPositionState = cameraPositionState
    ){
        Marker(
            //position = latLng,   <------This gives an error
            state = MarkerState(position = latLng),
            title = "Singapore",
            snippet = "Marker in Singapore"
        )
    }

我使用相同的导入

import com.google.maps.android.compose.GoogleMap
import com.google.maps.android.compose.Marker

除了在有标记状态的那一个中添加了这个

import com.google.maps.android.compose.MarkerState

我尝试删除它并仅使用位置,但它也不起作用。 我确定我使用的是 LatLng 类型的变量,所以我很确定不是这样

kotlin android-jetpack-compose google-maps-markers
1个回答
0
投票

造成这种差异的原因是这两个应用程序使用不同版本的 Google Maps Compose 库。

如果我们在官方 Github 存储库上查看 Google Maps Compose 库的 changelog,我们可以找到以下版本 2.0.0

entry

2.0.0 (2022-03-22)

特点
。 。 。

重大变更
标记和同级可组合项上的位置已被删除。使用 MarkerPositionState 来设置位置。

如果你检查两个应用程序的

build.gradle
文件,你会发现它们使用不同的依赖项:

// App with state uses Version >= 2.0.0
implementation 'com.google.maps.android:maps-compose:2.11.4'

// App with position uses Version < 2.0.0
implementation 'com.google.maps.android:maps-compose:1.0.1'
© www.soinside.com 2019 - 2024. All rights reserved.