
Google Maps JavaScript API Cookbook
By :

Applications can be mapped in different formats. Some of them show a map after a mouse click or an event, and some of them are shown directly in fullscreen mode.
This recipe will show you how to create a fullscreen map that will be used both in web or mobile applications.
As stated before, some recipes will show only the changed lines in the code in order to make way for more recipes. This recipe is the modified version of the previous recipe, Creating a simple map in a custom DIV element.
You can find the source code at Chapter 1/ch01_full_screen_map.html
.
You can easily create a simple fullscreen map by following the given steps:
full_screen_map.html
. Then, copy all of the code in the previous HTML file (map.html
) and paste it into this file.<style type="text/css"> #mapDiv { width: 800px; height: 500px; } </style>
width
and height
values are changed to 100%
in order to make the map full screen in the browser viewport. Also, the margin value of the body
element is changed to 0
to remove all the spaces around the map.<style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; } #mapDiv { width: 100%; height: 100%; } </style>
full_screen_map.html
file is stored, in your favorite browser and take a look at the result. You will see the map with navigation controls at the top-left corner and the base map control at the top-right corner that fills the entire browser area.Thus we have successfully created a simple fullscreen map.
The Google Maps JavaScript API uses the div
component of the HTML standard to show the map. The div
component gets its style and properties from CSS rules, which are defined at the top, in the <head>
element. The width
and height
attributes of #mapdiv
show that the div
component will fill the entire browser space. You can easily modify these width
and height
properties to change the map dimensions according to your needs.
The size of the map is directly related to CSS styles, and there is no direct relation between the map size and the Google Maps JavaScript API. The DIV
element that holds the Google Maps JavaScript API's base maps and overlays is just a blank container, and as the DIV
elements get larger, so does your map.
Change the font size
Change margin width
Change background colour