【问题标题】:How to show current location in HMS map with custom marker option?如何使用自定义标记选项在 HMS 地图中显示当前位置?
【发布时间】:2021-08-02 15:57:39
【问题描述】:

我在我的应用程序中使用了 HMS 地图。我正在使用位置工具包搜索选择某个位置,并使用自定义标记在地图中显示。我可以完美地获得纬度和经度。我也可以在几天前在地图上显示选定的位置。但目前无法显示。我没有更改代码中的任何内容。那么应该是什么问题呢?

private fun setMapWithCurrentLoc(lastLocation: android.location.Location?) {
    if (lastLocation != null) {
        val location = LatLng(lastLocation.latitude, lastLocation.longitude)
        if (map != null) {
            map!!.clear()
            map!!.addCircle(
                    CircleOptions()
                            .radius(500.0)
                            .center(location)
                            .clickable(false)
                            .fillColor(ContextCompat.getColor(requireContext(), R.color.purple_trans))
                            .strokeColor(ContextCompat.getColor(requireContext(), R.color.transparent))
                            .strokeWidth(1f)
            )
            map!!.addMarker(
                    MarkerOptions()
                            .position(location)
                            .icon(
                                    BitmapDescriptorFactory.fromBitmap(
                                            Utils.createCustomMarker(
                                                    requireContext(),
                                                    childUrl!!
                                            )
                                    )
                            )
                            .draggable(true)
            )
            map!!.animateCamera(
                    CameraUpdateFactory.newLatLngZoom(
                            LatLng(location.latitude, location.longitude),
                            currentZoomSetting.toFloat()
                    )
            )

        }
    }
}

【问题讨论】:

    标签: android kotlin huawei-mobile-services huawei-map-kit huawei-location-kit


    【解决方案1】:

    尝试更改一些代码并在带有com.huawei.hms.maps.SupportMapFragment 的Activity 中进行测试,它可以正常工作:

    override fun onMapReady(paramHuaweiMap: HuaweiMap?) {
        Log.i(TAG, "onMapReady: ")
        hMap = paramHuaweiMap
        hMap!!.isMyLocationEnabled = true
        setMapWithCurrentLoc(LatLng(48.893478, 2.334595))
    }
    
    private fun setMapWithCurrentLoc(location: LatLng) {
        var map = hMap
        if (map != null) {
            map!!.clear()
            map!!.addCircle(
                CircleOptions()
                    .radius(500.0)
                    .center(location)
                    .clickable(false)
                    .fillColor(ContextCompat.getColor(this, R.color.colorAccent))
                    .strokeColor(ContextCompat.getColor(this, R.color.colorAccent))
                    .strokeWidth(1f)
            )
            map!!.addMarker(
                MarkerOptions()
                    .position(location)
                    .icon(
                        BitmapDescriptorFactory.fromResource(
                            R.mipmap.ic_launcher
                        )
                    )
                    .draggable(true)
            )
    
            map!!.animateCamera(
                CameraUpdateFactory.newLatLngZoom(
                    LatLng(location.latitude, location.longitude),
                    11f
                )
            )
        }
    }
    

    实现 'com.huawei.hms:maps:6.0.0.301' 可以在您的代码中对此进行测试,看看是否有效。

    【讨论】:

    • 好的,我试试。谢谢
    • 当然,如果您需要任何进一步的帮助,请随时与我联系。 :)
    • 我使用 HMS Location Kit Document 解决了这个问题。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 2021-01-17
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多