如何使用jetpack compose获取MAP BOX中的所有四个角坐标

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

我想获取所有角(topLeft,topRight,bottomLeft,bottomRight)坐标(Lat,Lng)这里是代码

      MapboxMap(
        modifier = Modifier.fillMaxSize(),
        mapInitOptionsFactory = { context ->
            MapInitOptions(
                context = context,
                styleUri = Style.STANDARD,
            )
        },
        mapViewportState = mapViewportState,
        compassSettings = compassSettings,
        scaleBarSettings = scaleBarSetting,
        gesturesSettings = mapBoxUiSettings,
        attributionSettings = AttributionSettings {
            enabled = false
        },
    ) {
        MapEffect(key1 = Unit) { mapView ->
            mapView.mapboxMap.subscribeMapIdle(mapIdleCallback = {
                Log.d("Tag", "Idle ${mapView.mapboxMap.cameraState.center}")
            })
        }
    } // : MapboxMap

当mapbox空闲时

mapIdleCallback
现在被触发,我需要调用哪些方法来获取四个坐标。任何帮助将不胜感激。

android kotlin android-jetpack-compose mapbox jetpack
1个回答
0
投票

更新;经过更多的代码研究后我能够获得坐标

MapboxMap(
        modifier = Modifier.fillMaxSize(),
        mapInitOptionsFactory = { context ->
            MapInitOptions(
                context = context,
                styleUri = Style.STANDARD,
            )
        },
        mapViewportState = mapViewportState,
        compassSettings = compassSettings,
        scaleBarSettings = scaleBarSetting,
        gesturesSettings = mapBoxUiSettings,
        attributionSettings = AttributionSettings {
            enabled = false
        },
    ) {
        MapEffect(key1 = Unit) { mapView ->
            mapView.mapboxMap.subscribeMapIdle(mapIdleCallback = {
                val coordinateBounds =
                    mapView.mapboxMap.coordinateBoundsForCamera(mapView.mapboxMap.cameraState.toCameraOptions())
                // Extract individual corner coordinates
                val southwest = coordinateBounds.southwest
                val northeast = coordinateBounds.northeast
                // Calculate other corner coordinates
                val northwest = Point.fromLngLat(southwest.longitude(), northeast.latitude())
                val southeast = Point.fromLngLat(northeast.longitude(), southwest.latitude())
                list = listOf(
                    southwest,
                    northwest,
                    northeast,
                    southeast,
                    southwest
                )
            })
        }
    } // : MapboxMap

我正在寻找的方法是

mapView.mapboxMap.cameraState.toCameraOptions()
,它为我提供了northEastsouthWest坐标,然后我可以使用基本的地图协调技术获得其他两个坐标。

© www.soinside.com 2019 - 2024. All rights reserved.