How to Style Google Maps with Snazzy Maps

·

4 min read

Google Maps is a popular mapping service that provides a wide range of features for web developers and designers. One of the most important aspects of Google Maps is its styling, which allows developers to customize the look and feel of maps to match their website's design. In this blog post, we will explore the styling of Google Maps and how to use Snazzy Maps to create custom styles.

Styling Google Maps

Google Maps provides a wide range of styling options that can be used to customize the look and feel of maps. These options include changing the color of roads, water, and other map features, as well as adding custom icons and labels. Styling can be applied to maps using the Google Maps JavaScript API, which provides a set of functions and options for customizing maps. To style a Google Map, you can use the MapOptions object, which provides a set of properties for customizing the map's appearance. These properties include backgroundColor, zoomControl, mapTypeControl, streetViewControl, and styles. The styles property is the most important property for customizing the map's appearance, as it allows you to specify an array of custom styles for the map.

Using Snazzy Maps

Snazzy Maps is a repository of different styles for Google Maps aimed towards web designers and developers. All styles are licensed under creative commons and are completely free to use. Snazzy Maps provides a wide range of styles that can be used to customize the look and feel of maps, including styles for roads, water, and other map features. To use Snazzy Maps, you can simply browse the styles on the Snazzy Maps website and copy the JSON code for the style you want to use. You can then paste this code into the styles property of the MapOptions object when creating a new map using the Google Maps JavaScript API. Here's an example of how to use Snazzy Maps to create a custom style for a Google Map:

<!DOCTYPE html>
<html>
  <head>
    <title>Styled Google Map</title>
    <style>
            html,
            body {
                height: 100%;
                margin: 0;
                padding: 0;
            }
            #map {
                height: 100%;
            }    
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: 37.7749, lng: -122.4194},
          zoom: 13,
          styles: [
            {
              "featureType": "water",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#e9e9e9"
                },
                {
                  "lightness": 17
                }
              ]
            },
            {
              "featureType": "landscape",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#f5f5f5"
                },
                {
                  "lightness": 20
                }
              ]
            },
            {
              "featureType": "road.highway",
              "elementType": "geometry.fill",
              "stylers": [
                {
                  "color": "#ffffff"
                },
                {
                  "lightness": 17
                }
              ]
            },
            {
              "featureType": "road.highway",
              "elementType": "geometry.stroke",
              "stylers": [
                {
                  "color": "#ffffff"
                },
                {
                  "lightness": 29
                },
                {
                  "weight": 0.2
                }
              ]
            },
            {
              "featureType": "road.arterial",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#ffffff"
                },
                {
                  "lightness": 18
                }
              ]
            },
            {
              "featureType": "road.local",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#ffffff"
                },
                {
                  "lightness": 16
                }
              ]
            },
            {
              "featureType": "poi",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#f5f5f5"
                },
                {
                  "lightness": 21
                }
              ]
            },
            {
              "featureType": "poi.park",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#dedede"
                },
                {
                  "lightness": 21
                }
              ]
            },
            {
              "elementType": "labels.text.stroke",
              "stylers": [
                {
                  "visibility": "on"
                },
                {
                  "color": "#ffffff"
                },
                {
                  "lightness": 16
                }
              ]
            },
            {
              "elementType": "labels.text.fill",
              "stylers": [
                {
                  "saturation": 36
                },
                {
                  "color": "#333333"
                },
                {
                  "lightness": 40
                }
              ]
            },
            {
              "elementType": "labels.icon",
              "stylers": [
                {
                  "visibility": "off"
                }
              ]
            },
            {
              "featureType": "transit",
              "elementType": "geometry",
              "stylers": [
                {
                  "color": "#f2f2f2"
                },
                {
                  "lightness": 19
                }
              ]
            },
            {
              "featureType": "administrative",
              "elementType": "geometry.fill",
              "stylers": [
                {
                  "color": "#fefefe"
                },
                {
                  "lightness": 20
                }
              ]
            },
            {
              "featureType": "administrative",
              "elementType": "geometry.stroke",
              "stylers": [
                {
                  "color": "#fefefe"
                },
                {
                  "lightness": 17
                },
                {
                  "weight": 1.2
                }
              ]
            }
          ]
        });
      }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
  </body>
</html>

As you can see in the code snippet above, we have created a new Google Map using the google.maps.Map() constructor and passed in the MapOptions object as the second argument. The MapOptions object includes the center, zoom, and styles properties. The styles property is an array of custom styles that we have copied from Snazzy Maps.


To use Snazzy Maps in your own project, you can simply browse the styles on the Snazzy Maps website and copy the JSON code for the style you want to use. You can then paste this code into the styles property of the MapOptions object when creating a new map using the Google Maps JavaScript API.