-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path3-init.html
113 lines (100 loc) · 3.57 KB
/
3-init.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Init - Google Maps API demo - August - Let's Write</title>
<link rel="canonical" href="https://www.letswrite.tw/google-map-api-marker-custom/">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
.container {
padding-top: 30px;
padding-bottom: 30px;
}
#map {
background: #CCC;
}
.fixed-bottom {
position: fixed;
left: 16px;
bottom: 0;
max-width: 320px;
}
</style>
<link rel="shortcut icon" href="https://letswritetw.github.io/letswritetw/dist/img/logo_512.png"/>
<!-- Google Tag Manager-->
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PGQ9WQT');
</script>
</head>
<body>
<!-- Google Tag Manager (noscript)-->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PGQ9WQT" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<div id="app" class="container">
<div class="row">
<div class="col">
<div id="map" class="embed-responsive embed-responsive-16by9"></div>
</div>
</div>
<div class="row fixed-bottom">
<div class="col">
<div class="alert alert-info" role="alert">
Let's Write 筆記文:<br/>
<a href="https://letswrite.tw/google-map-api-marker-custom/" target="_blank">Google Maps API學習筆記-1</a>
</div>
</div>
</div>
</div>
<!-- 將 YOUR_API_KEY 替換成你的 API Key 即可 -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" async defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<!-- map -->
<script>
const googleMap = new Vue({
el: '#app',
data: {
map: null
},
methods: {
// init google map
initMap() {
// 預設顯示的地點:台北市政府親子劇場
let location = {
lat: 25.0374865, // 經度
lng: 121.5647688 // 緯度
};
// 建立地圖
this.map = new google.maps.Map(document.getElementById('map'), {
center: location, // 中心點座標
zoom: 16, // 1-20,數字愈大,地圖愈細:1是世界地圖,20就會到街道
/*
roadmap 顯示默認道路地圖視圖。
satellite 顯示 Google 地球衛星圖像。
hybrid 顯示正常和衛星視圖的混合。
terrain 顯示基於地形信息的物理地圖。
*/
mapTypeId: 'terrain'
});
// 放置marker
let marker = new google.maps.Marker({
position: location,
map: this.map
});
}
},
created() {
window.addEventListener('load', () => {
this.initMap();
});
}
});
</script>
</body>
</html>