html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<head>
<title>Simple Google Maps Example</title>
<!-- Import the google map sdk api -->
<!-- replace YOUR_API_KEY at the end of url with your api -->
<!--
1. Go to Google Cloud Console:
https://console.cloud.google.com/
2. Create a New Project:
Click on the project dropdown at the top and select "New Project."
Name your project and create it.
3. Enable Google Maps JavaScript API:
Go to APIs & Services > Library.
Search for "Google Maps JavaScript API" and click Enable.
4. Create an API Key:
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
body {
margin: 0;
}
#map {
width: 100dvw;
height: 100dvh;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function initMap() {
// Create a map object and specify the DOM element for display.
var map = new google.maps.Map(
document.getElementById('map'),
{
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
// Add a marker at the center
let marker = new google.maps.Marker({
position: {lat: -34.397, lng: 150.644},
map: map,
title: 'Hello World!'
});
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run