質問編集履歴

3

2018/04/14 21:40

投稿

memu2
memu2

スコア16

test CHANGED
File without changes
test CHANGED
@@ -250,4 +250,6 @@
250
250
 
251
251
 
252
252
 
253
- ,
253
+ 追記3:
254
+
255
+ ごめんやん

2

jsonコードを追記

2018/04/14 21:39

投稿

memu2
memu2

スコア16

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- 追記
31
+ 追記1:html
32
32
 
33
33
  ```html
34
34
 
@@ -197,3 +197,57 @@
197
197
  </html>
198
198
 
199
199
  ```
200
+
201
+ 追記2:json
202
+
203
+ ```json
204
+
205
+ [
206
+
207
+ {
208
+
209
+ "body": "\u3002",
210
+
211
+ "lat": 35.668416,
212
+
213
+ "lng": 139.728201,
214
+
215
+ "name": "sample1",
216
+
217
+ },
218
+
219
+ {
220
+
221
+ "body": "\u3002",
222
+
223
+ "lat": 35.868416,
224
+
225
+ "lng": 139.728201,
226
+
227
+ "name": "sample2",
228
+
229
+ },
230
+
231
+ {
232
+
233
+ "body": "\u4e43\u3002",
234
+
235
+ "lat": 35.674565,
236
+
237
+ "lng": 139.71699,
238
+
239
+ "name": "sample3",
240
+
241
+ }
242
+
243
+ ]
244
+
245
+ ```
246
+
247
+ このサイトを参考にjsonへの書き込み処理と読み込み処理を記述しました。
248
+
249
+ [http://sanvarie.hatenablog.com/entry/2015/12/06/104506](http://sanvarie.hatenablog.com/entry/2015/12/06/104506)
250
+
251
+
252
+
253
+ ,

1

htmlのコードを追加

2018/04/14 06:40

投稿

memu2
memu2

スコア16

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,175 @@
25
25
 
26
26
 
27
27
  ちなみに当該htmlファイルとjquery、javascript、jsonファイルはすべて同一ディレクトリ内に置いてあります。
28
+
29
+
30
+
31
+ 追記
32
+
33
+ ```html
34
+
35
+ <!DOCTYPE html>
36
+
37
+ <html>
38
+
39
+ <head>
40
+
41
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
42
+
43
+ <meta charset="utf-8">
44
+
45
+ <title>Info window with <code>maxWidth</code></title>
46
+
47
+ <style>
48
+
49
+ /* Always set the map height explicitly to define the size of the div
50
+
51
+ * element that contains the map. */
52
+
53
+ #map {
54
+
55
+ height: 100%;
56
+
57
+ }
58
+
59
+ /* Optional: Makes the sample page fill the window. */
60
+
61
+ html, body {
62
+
63
+ height: 100%;
64
+
65
+ margin: 0;
66
+
67
+ padding: 0;
68
+
69
+ }
70
+
71
+ </style>
72
+
73
+ <script src="https://maps.googleapis.com/maps/api/js?key=MY_APIKEY">
74
+
75
+ </script>
76
+
77
+ <script>
78
+
79
+ function initMap(){
80
+
81
+ // Map options
82
+
83
+ var options = {
84
+
85
+ zoom:5,
86
+
87
+ center:{lat:42.999988, lng:-71.888888}
88
+
89
+ };
90
+
91
+
92
+
93
+ // Add map
94
+
95
+ var map = new google.maps.Map(document.getElementById('map'), options);
96
+
97
+ }
98
+
99
+
100
+
101
+
102
+
103
+ function loadJson_and_addMarkers(){
104
+
105
+ var json = [];
106
+
107
+ $(function(){
108
+
109
+ $.getJSON("new_data.json" , function(data) {
110
+
111
+ json = data;
112
+
113
+ });
114
+
115
+ });
116
+
117
+ for(var i = 0;i < json.length;i++){
118
+
119
+ addMarker(json[i]);
120
+
121
+ }
122
+
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ function addMarker(json){
134
+
135
+ var marker = new google.maps.Marker({
136
+
137
+ positions:{lat:json.lat, lng:json.lng},
138
+
139
+ map:map
140
+
141
+ });
142
+
143
+
144
+
145
+ var content = '<h1>' + json.name + '</h1>'+
146
+
147
+ '<div id="bodycontent">' + json.body + '</div>';
148
+
149
+
150
+
151
+ var infowindow = new google.maps.InfoWindow({
152
+
153
+ content:content
154
+
155
+ });
156
+
157
+
158
+
159
+ marker.addListener('click', function(){
160
+
161
+ infowindow.open(map, marker);
162
+
163
+ });
164
+
165
+ }
166
+
167
+
168
+
169
+
170
+
171
+ </script>
172
+
173
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript">
174
+
175
+ </script>
176
+
177
+ </head>
178
+
179
+
180
+
181
+ <body onload="initMap()">
182
+
183
+ <div id="map"></div>
184
+
185
+ <form>
186
+
187
+ <p>
188
+
189
+ <input type="button" id="btn" value="make Markers" onclick="loadJson_and_addMarkers()" />
190
+
191
+ </p>
192
+
193
+ </form>
194
+
195
+ </body>
196
+
197
+ </html>
198
+
199
+ ```