Here are the minimum CSS rules that Google advises you to use, in a separate CSS file, or within an HTML style tag, e.g. <style type="text/css">...</style>
.
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 400px;
}
Google recommends that you declare a true DOCTYPE
within your web application.
<!DOCTYPE html>
Use the following script tag to load the Google Maps JavaScript API in your application.
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initialize">
</script>
Create an HTML element to hold the map.
<div id="map"></div>
Here is a very simple example displaying a Map and a Marker.
function initialize() {
// Create a LatLng object
// We use this LatLng object to center the map and position the marker
var center = new google.maps.LatLng(50,0);
// Declare your map options
var mapOptions = {
zoom: 4,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create a map in the #map HTML element, using the declared options
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
// Create a marker and place it on the map
var marker = new google.maps.Marker({
position: center,
map: map
});
}
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 400px;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initialize() {
// Create a LatLng object
// We use this LatLng object to center the map and position the marker
var center = new google.maps.LatLng(50, 0);
// Declare your map options
var mapOptions = {
zoom: 4,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create a map in the #map HTML element, using the declared options
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
// Create a marker and place it on the map
var marker = new google.maps.Marker({
position: center,
map: map
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initialize" async defer></script>
</body>
</html>
Please read this topic's Remarks for more information.