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.
- You could go to
“save” and “publish” it:
save both Preview ID and Stye ID to somewhere.
Then Export the Map style:
Save the Json String to Android Studio Project ---- res ---- raw ----mapstyle_simple.json
- 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") }