【问题标题】:Google maps theme谷歌地图主题
【发布时间】:2018-09-18 09:08:48
【问题描述】:

我已经在我的 Android 应用程序中实现了谷歌地图,直到几天前一切看起来都很干净。以前的地图如下图所示

现在地图有了类似于下图的新外观

我没有更改或更新实施中的任何内容,但地图上有黑线,难以阅读这些地方。

感谢任何帮助。 谢谢

注意:我从谷歌下载了图片以供参考,请忽略 xml 布局更改。

【问题讨论】:

  • 第二张图片来自优步。你能用你应用的屏幕替换吗
  • @Sreehari 地图看起来也与我应用中的第二张图片相似。
  • 你试过谷歌地图的地形视图吗 map.setMapType(GoogleMap.MAP_TYPE_TERRAIN); map.invalidate();?

标签: android google-maps maps android-theme


【解决方案1】:

我猜你可能会添加地图主题,如果添加请删除或更改主题

    //Custom Theme
    MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(this.context, R.raw.my_map_style);
    map.setMapStyle(style);

更换主题请参考here

here 创建主题。

【讨论】:

    【解决方案2】:

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

    然后像这样申请你的 onMapready()

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

    【讨论】:

      【解决方案3】:

      在样式 json 文件中重写。尝试改变不同的颜色代码。

      java代码

      MapStyleOptions mapStyleOptions = MapStyleOptions.loadRawResourceStyle(activity, 
      R.raw.map_style);
      googleMap.setMapStyle(mapStyleOptions);
      

      原始/map_style.json 文件

       [
        {
          "featureType": "administrative",
          "elementType": "all",
          "stylers": [
            {
              "saturation": "40"
            },
            {
              "lightness": "5"
            }
          ]
        },
        {
          "featureType": "administrative",
          "elementType": "geometry.stroke",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "administrative",
          "elementType": "labels.text",
          "stylers": [
            {
              "hue": "#ff0000"
            },
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "administrative",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "color": "#000000"
            }
          ]
        },
        {
          "featureType": "administrative.locality",
          "elementType": "labels.text",
          "stylers": [
            {
              "visibility": "simplified"
            },
            {
              "color": "#cb561a"
            }
          ]
        },
        {
          "featureType": "administrative.locality",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "color": "#858585"
            }
          ]
        },
        {
          "featureType": "administrative.neighborhood",
          "elementType": "geometry.stroke",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "administrative.neighborhood",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "color": "#858585"
            }
          ]
        },
        {
          "featureType": "administrative.neighborhood",
          "elementType": "labels.icon",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "color": "#00467f"
            }
          ]
        },
        {
          "featureType": "administrative.land_parcel",
          "elementType": "all",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "administrative.land_parcel",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "administrative.land_parcel",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "color": "#a8a8a8"
            }
          ]
        },
        {
          "featureType": "landscape",
          "elementType": "all",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "hue": "#ffc800"
            }
          ]
        },
        {
          "featureType": "landscape.man_made",
          "elementType": "all",
          "stylers": [
            {
              "hue": "#ffc800"
            },
            {
              "saturation": "25"
            },
            {
              "lightness": "42"
            }
          ]
        },
        {
          "featureType": "landscape.man_made",
          "elementType": "geometry",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "lightness": "8"
            },
            {
              "gamma": "0.75"
            },
            {
              "saturation": "-6"
            },
            {
              "hue": "#ffc600"
            }
          ]
        },
        {
          "featureType": "landscape.man_made",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "landscape.man_made",
          "elementType": "geometry.stroke",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "weight": "1.77"
            }
          ]
        },
        {
          "featureType": "poi",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "poi",
          "elementType": "labels.text",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "poi",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "color": "#aeaeae"
            },
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "poi.park",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "color": "#8bd188"
            },
            {
              "lightness": "41"
            }
          ]
        },
        {
          "featureType": "poi.park",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "color": "#949595"
            },
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "road",
          "elementType": "all",
          "stylers": [
            {
              "saturation": -100
            },
            {
              "lightness": 45
            }
          ]
        },
        {
          "featureType": "road",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "visibility": "on"
            },
            {
              "hue": "#ff0000"
            }
          ]
        },
        {
          "featureType": "road",
          "elementType": "labels.text.fill",
          "stylers": [
            {
              "color": "#686868"
            }
          ]
        },
        {
          "featureType": "road.highway",
          "elementType": "all",
          "stylers": [
            {
              "visibility": "simplified"
            }
          ]
        },
        {
          "featureType": "road.highway",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "color": "#ffffff"
            }
          ]
        },
        {
          "featureType": "road.highway",
          "elementType": "geometry.stroke",
          "stylers": [
            {
              "weight": "1.03"
            }
          ]
        },
        {
          "featureType": "road.arterial",
          "elementType": "labels.icon",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "transit",
          "elementType": "all",
          "stylers": [
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "transit",
          "elementType": "labels",
          "stylers": [
            {
              "visibility": "simplified"
            }
          ]
        },
        {
          "featureType": "water",
          "elementType": "all",
          "stylers": [
            {
              "color": "#b3e9ff"
            },
            {
              "visibility": "on"
            }
          ]
        },
        {
          "featureType": "water",
          "elementType": "geometry.fill",
          "stylers": [
            {
              "saturation": "-35"
            },
            {
              "color": "#b6e0f3"
            }
          ]
        },
        {
          "featureType": "water",
          "elementType": "labels.icon",
          "stylers": [
            {
              "color": "#86c1ea"
            }
          ]
        }
      ]
      

      【讨论】:

        【解决方案4】:

        您可以使用样式 JSON 文件。这里我有attached 示例 json。您可以下载并应用您的项目。

        try {
             boolean success = mMap.setMapStyle(
                            MapStyleOptions.loadRawResourceStyle(
                                    this, R.raw.maps_style));
        
             // mMap : It is the object of a map. 
        
             if (!success) {
                 Log.e("tag", "Style parsing failed.");
                }
         } catch (Resources.NotFoundException e) {
                    Log.e("tag", "Can't find style. :" + e);
         }
        

        您也可以从google.developer 网站获取样式。 谢谢希望这会对你有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-03-17
          • 2011-10-26
          • 2012-03-15
          • 2014-04-05
          • 1970-01-01
          • 2011-12-26
          • 2011-04-26
          相关资源
          最近更新 更多