1

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)
}
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
Matrix
  • 503
  • 3
  • 17

1 Answers1

0

There is a solution for this problem.

  1. You could go to this site to make a self style map, Here's my test:

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")
    }

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108