Home > Blockchain >  Huawei Map Kit Style Feature
Huawei Map Kit Style Feature

Time:10-27

I'm developing a reference app. The app has fullscreen map via Huawei Map Kit with style file. When users open app for the first time, map style not working correctly. But style works correctly after user reopen the app.

I added code blocks and app's screenshots. Any help would be appreciated

Map kit version: implementation 'com.huawei.hms:maps:5.2.0.300'

override fun onMapReady(map: HuaweiMap) {
    Log.d(TAG, "onMapReady: ")
    hMap = map
    hMap?.uiSettings?.isMyLocationButtonEnabled = false
    hMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(48.893478, 2.334595), 10f))
    setSimpleStyle()
}

fun setSimpleStyle() {
    val styleOptions = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_simple)
    hMap?.setMapStyle(styleOptions)
}

CodePudding user response:

There is a solution for this problem.

  1. You could go to enter image description here

    1. “save” and “publish” it:

      save both Preview ID and Stye ID to somewhere.

    enter image description here

    1. Then Export the Map style:

      Save the Json String to Android Studio Project ---- res ---- raw ----mapstyle_simple.json

    enter image description here

    1. finally in the code :
        override fun onMapReady(map: HuaweiMap) {
            Log.d(TAG, "onMapReady: ")
            hMap = map
            hMap?.uiSettings?.isMyLocationButtonEnabled = false
            hMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(48.893478, 2.334595), 10f))
            setSimpleStyle()
        }
    
        fun setSimpleStyle() {
            val styleOptions = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_simple)
            hMap?.setMapStyle(styleOptions)
            hMap?.setStyleId("your style id saved above")
            hMap?.previewId("your preview id saved above")
        }
    
    
  • Related