react-native-maps 中的自定义地图样式未呈现,恢复为 basic/standard 地图样式

Custom map styling in react-native-maps not rendering, reverts to basic/standard map style

正在使用 ReactNative 应用程序,我正在尝试编辑地图样式。

我正在按照“https://github.com/react-native-community/react-native-maps”上的说明进行操作。

对于 IOS,文档建议如下。

即:

1) 添加从 https://mapstyle.withgoogle.com/].

生成的 mapStyle = [JSON

2) 导入 PROVIDER_GOOGLE

3) 添加 'customMapStyle' & 'provider' 道具(见下文)

然而,即使我已经手动检查了JSON(即颜色都是黑色和灰色,按照我想要的自定义地图)渲染的地图仍然是标准的蓝色和青菜?

奇怪的是,我的标记从别针变成了一些 android 看起来像别针,所以发生了一些事情。

欢迎任何想法。

谢谢

import MapView, { PROVIDER_GOOGLE } from 'react-native-maps'

MapStyle = [ ... ]

render() {
  return (
    <MapView
      region={this.state.region}
      onRegionChange={this.onRegionChange}
      provider={PROVIDER_GOOGLE}
      customMapStyle={MapStyle}
    />
  );
}

我犯了同样的错误,从本地 json 文件中获取样式,但没有成功。这是一个变通方法 - 将 json 样式保存在 var 中并将其传递给 customMapStyle。 读一读:Custom google map styles in React Native - medium.com

首先进入官方,即 https://mapstyle.withgoogle.com/ 并获取 json 作为您的样式值并复制到资源中的原始文件夹

然后像这样在你的 onMapready() 上应用

MapStyleOptions mapStyleOptions = MapStyleOptions.loadRawResourceStyle(this, R.raw.style_json);
mGoogleMap.setMapStyle(mapStyleOptions);

自定义样式对我不起作用的原因是 JSON 具有过时的参数,因此地图默认为默认主题。作为ser fiy pointed out, make sure to download the JSON from https://mapstyle.withgoogle.com/