## The Plan

In this tutorial we'll walk through the process of creating a branded Google map for an imaginary client. Our map will include three key features:

1. Custom markers at each of the client's branch locations
2. The client's logo in a fixed position on the map
3. Map theming which compliments the client's branding

In this case, our imaginary client is going to be "The Hobby Shoppe", purveyors of fine board games and other hobby paraphernalia around the city of Melbourne, Australia.

## Creating the Base Map

We'll get the ball rolling by creating a basic map centered on the city of Melbourne. After we add our branch markers we'll refine the center position of the map, but for now we'll start by finding the right latitude and longitude in order to show the city as a whole.

### Initial Latitude and Longitude

To do this go to Google Maps and search for Melbourne, then zoom in just a little so you're not including unpopulated areas. As you adjust the position of the map you'll notice the URL changes to reflect your new latitude, longitude and zoom level. When you have the map positioned where you like, copy the URL somewhere for later reference, e.g:

After the @ symbol in the URL you'll see comma separated values for the latitude, longitude and zoom level: -37.8046274,144.972156,12z

The first value -37.8046274 is the latitude, the second value 144.972156 is the longitude, and the 12z value means the zoom level is set to 12. We're now going to plug these values into a basic map.

### Basic Markup

Create a blank HTML document and add the following code:

With this markup we have created an HTML document including a div with the id map-canvas which will hold our map. We've also added some basic CSS to size and position the map-canvas div.

Lastly, we've loaded the required script from the Google Map API with:

and we've created a JavaScript function to set the basic options of the map and load it into our empty div.

Note: see how the values we took from the Google Maps URL earlier have been used in the centerPos and zoomLevel variables, which are in turn used in the mapOptions array. The centerPos variable uses the comma separated latitude and longitude values of -37.8046274,144.972156, and the zoomLevel variable uses the value of 12.

Save your HTML file and open it up in any browser. Your base map should look a bit like this:

The next step is to find the latitude and longitude for each of the client's branch locations, so we can create markers for them at those positions. The easiest way to do this is to find each branch address via a Google Maps search and grab the latitude and longitude from there.

### Find Latitude and Longitude of Each Branch

Head back to Google Maps again and run a search for each branch location. Assuming the client has given you the addresses of each location, you can simply search for that address and a marker will appear on the map. Right click that marker and choose What's here? from the context menu.

A small popup will appear at the top left of the map displaying details for this marker including latitude and longitude:

### Add Locations to the Initialize Function

Make a note of the latitude and longitude for each of the branch locations you want to add to your map. In the case of "The Hobby Shoppe" we have seven branch locations and we'll add markers for each by inserting the following code just before the end of our map's initialize() function, after the map = new google.maps.Map... line:

In this code we are first creating an array of branch locations with the name, latitude and longitude of each. We're then iterating through that array to add each location as a marker to the map, with the title to be displayed as a tool tip if the marker is hovered over.

But wait, there's something wrong with this picture. We added seven locations, and yet only six markers appear. Why?

It's simply because our seventh marker is just out of view based on the initial latitude and longitude we set for the map, so we need to refine that center position.

### Adjusting the Map Center Position

Now that we have all our markers in place we can refine the starting position of the map to ensure they're all visible on load. To do that we'll add a button which we can click to give us new co-ordinates once we find the perfect map starting position.

Add this button code to your page, anywhere in the body section:

Now you can move your map around and then click the new Get Map Co-ords button when you find the right spot.

The latitude, longitude and zoom level of your position will be written to your console, so make sure you have the Chrome Dev Tools or Firebug console open.

Update your map's center option with the new latitude and longitude, as well as the zoom option if that has changed too:

Save and refresh your map and now all seven map markers should be visible. When you're happy with the refined center position you can remove the Get Map Co-ords button code.

Now that we have all the markers in place and visible for the branch locations we're going to convert them into a custom image, one that goes with the client branding and the style of map. Any image created for use as a map marker should have a transparent background, e.g.

Place your custom marker in an "images" folder, relative to the folder your base map is in, then add the following variable directly under the locations variable you created previously:

Then add an extra option of icon: image to the for loop we created earlier to place map markers. Passing this variable into the map marker generation options specifies that you want the marker icons to be replaced with your custom image:

Take another look at your map and you should now see little houses at each of the seven branch locations:

We're now going to add the client's logo in such a way that it will remain the same size and in the same position regardless of where the map is zoomed or panned to.

The only elements of a Google Map that don't move with panning and zooming are the control UI elements, typically used for things like engaging street view or switching map types. However, we can use the custom control API equally well to place a logo on the screen. We'll also have our new custom control reset the zoom and center position of the map when clicked so as well as displaying the logo it performs a useful UI function.

Start by adding your client's logo image into the same "images" folder you placed your custom marker image. Then add the following JavaScript function just before your existing initialize() function:

When executed, this function will create a control UI element 600px by 116px in size, using the logo image as its background. It will also create a listener which will reset the center and zoom of the map if the logo is clicked.

Then, at the end of your initialize() function, insert the following code:

When the initialize() function runs it will now call the LogoControl() function we just created and add its output into the map controls.

Your map should now look like this:

## Coloring the Map

To setup the colors of your map you'll almost certainly want to use Google's Styled Map Wizard in order to get rapid visual feedback on your choices.

The Feature type menu in the wizard gives you a range of map components available for styling. They're organized from the most general, down to most specific. At the most general level you can apply color choices to the All feature type, in order to affect everything on the map equally. On the other end of the spectrum you can drill down as specifically as All > Transit > Station > Bus for example.

With a Feature type selected you can then also make a selection from the Element type menu to determine if you want your color choices to influence the feature's geometry or its labels (such as the little text labels you see floating around the map). Furthermore, you can then also select either the fill or stroke color to modify.

When it comes to choosing colors there are two main areas you'll want to work with; the Colour panel and the Hue panel. The Colour panel will apply a color hexcode flatly to the features and elements you have selected, whereas the Hue panel will tint your selection with a range of lightness and darkness influenced by each element's original color.

As a general rule you should start by applying a Hue to the most general levels of your map so you have some uniformity in your color scheme - you could compare this to a base coat of paint. From there you can then drill down to "paint" over the top with flat Colour settings for more specific features and elements.

### Our Map

Start by searching in the wizard for "Melbourne" and then positioning the preview map to show you approximately the same area you set your own map to show.

Under the Feature type menu in the wizard select All, and under the Element type menu select Geometry. Then check the Hue box and click the color bar until you get a value of somewhere around #ffa200. For some reason you can't directly enter a value in this field, so you have to get it as close as you can by clicking. Then check the Invert lightness box, activate the Saturation setting and drag it to 35, activate the Lightness setting and place it at 50, and activate the Gamma setting and get it as close as you can to 1.3.

These settings should have tinted your entire map like so:

Your map looks a little funny at this stage because we're aiming to make a colorful map, so the tint settings here have been amped up to ensure there are no drab areas anywhere. The excessively bright areas will be overridden with more subdued colors in subsequent steps.

### Toning Things Down

Now that you have your first style applied, click the Add button in the top right corner of the Map Style panel, (located at the right side of the map wizard). Clicking this button creates a second style named "Style 1" under which you can select different elements and apply new styles.

With "Style 1" selected in the Map Style panel and All still selected under Feature type click the Labels option in the second list of the Element type menu. Check the Hue box and again set it to a value of #ffa200 so your labels are all tinted instead of being bright blue or green as you see in the image above.

Click the Add button on the Map Style panel to create another new style, then click Water in the second list of the Feature type menu. Under the Element type menu select Geometry. Check the Color box and enter a color hexcode of #8F9B98.

### The Remaining Styles

You should now know how to create new styles, by selecting Feature type and Element type menu items. Go ahead and add the rest of these styles one at a time in the styled map wizard:

• Feature type: All
• Element type: All > Labels > Text > Fill
• Feature type: All
• Element type: All > Labels > Text > Stroke
• Color: #6a5035
• Feature type: All > Landscape > Man made
• Element type: All > Geometry
• Color: #9f8053
• Feature type: All > Landscape > Natural
• Element type: All > Geometry
• Color: #9c9743
• Feature type: All > Point of interest
• Element type: All > Geometry
• Color: #ACA74C
• Feature type: All > Road
• Element type: All > Geometry > Fill
• Color: #d3b681
• Feature type: All > Road
• Element type: All > Geometry > Stroke
• Color: #644F34
• Feature type: All > Road > Arterial
• Element type: All > Geometry > Fill
• Color: #c6a15e
• Feature type: All > Road > Local
• Element type: All > Geometry > Fill
• Color: #b09061
• Feature type: All
• Element type: All > Labels > Text > Stroke
• Color: #483521
• Feature type: All > Transit > Line
• Element type: All > Geometry
• Color: #876b48
• Feature type: All > Transit > Station
• Element type: All > Geometry
• Color: #a58557

### Exporting Map Styles

Once you've added all these styles you're ready to export the settings the wizard has created and add them into your map. On the Map Style panel click the Show JSON button at the bottom. You'll see a white window appear, displaying an array of JavaScript options.

Copy all the text from that window between the opening [ and closing ], i.e. everything but the main heading.

At the beginning of your initialize() function add this new line:

Position your cursor before the ; then paste in the code you copied from the styled map wizard. You should end up with:

Then at the very end of the initialize() function add these three lines:

These lines of code apply all the color scheme data you just pulled in from the styled map wizard to your map. Take another look and it should now appear with all your styling selections in place:

Check out the live demo so you can see the map at its proper size and play around with zooming and panning here.

## Wrapping Up

As a final touch you might also like to add a frame effect around your map to further compliment the styling. Replace the existing #map-canvas { ... } CSS in your file with this:

As you can see, there's quite a lot you can do with Google Maps beyond just basic embedding. In this tutorial we've still only explored a couple of aspects of the Google Maps API - you can read more about all the other functions offered by the API in the Google Map help docs.

If you want to take this tutorial even further you could also try adding your own custom styled zoom and pan controls (custom control docs), and creating info windows which pop up when markers are clicked . These popups could hold details like phone number and street address (info windows docs).

Give these techniques a try next time a client asks you to include a Google Map in their site. You might just get a bonus!