android 在谷歌Map上绘制标记路径线覆盖运河和河流

zysjyyx4  于 2023-05-27  发布在  Android
关注(0)|答案(1)|浏览(147)

我在做一个能在Map上保存船只位置的应用程序。我可以在谷歌Map的撰写框中画标记(见截图),但我想通过一个路径链接它们。我可以假设河流和运河总是靠近一条纤道,所以我可以使用谷歌交通API并获得步行路线,但这不是最好的解决方案。如何在GoogleMap上找到水?有没有一种方法可以做到这一点,这样我就可以在运河和河流上画一条线?Map上的绿色是伦敦的一条运河。

xytpbqjk

xytpbqjk1#

使用可组合函数为Map添加折线

您可以使用Polyline组合函数在河流/运河上创建自己的路径。
我尝试使用自己的LatLng值重现一个示例,在河的顶部创建一条路径。
下面是代码的样子:

val center = LatLng(14.563063, 121.060071)
val marker1 = LatLng(14.565079, 121.055974)
val marker2 = LatLng(14.561618, 121.064759)
val cameraPositionState = rememberCameraPositionState {
   position = CameraPosition.fromLatLngZoom(center, 15f)
}
GoogleMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState
) {
    Marker(
        state = MarkerState(position = marker1),
        title = "Marker 1",
        snippet = "First Marker!"
    )
    Marker(
        state = MarkerState(position = marker2),
        title = "Marker 2",
        snippet = "Second Marker!"
    )
    Polyline(
        points = listOf(
            LatLng(14.565079, 121.055974),
            LatLng(14.565223, 121.056668),
            LatLng(14.564586, 121.059012),
            LatLng(14.563079, 121.060970),
            LatLng(14.561647, 121.062719),
            LatLng(14.561152, 121.064543),
            LatLng(14.561618, 121.064759)
        )
        ,color = Color.Black
    )
}

这是它在我的模拟器中的样子:

我希望这对你有帮助!

相关问题