質問編集履歴
2
javascirptを追記しています。
test
CHANGED
File without changes
|
test
CHANGED
@@ -107,3 +107,365 @@
|
|
107
107
|
|
108
108
|
|
109
109
|
2行目の`<!-- map -->`の部分にコードを入れています。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
再度追記いたしました。
|
114
|
+
|
115
|
+
ヘッダー内で次を読み込んでいます。
|
116
|
+
|
117
|
+
```ここに言語を入力
|
118
|
+
|
119
|
+
<!-- googlemap api -->
|
120
|
+
|
121
|
+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBQHa0hNePDGP1oIKswgeyeY84pHhbvAJQ"></script>
|
122
|
+
|
123
|
+
<script src="<?php echo get_template_directory_uri(); ?>/js/googlemap.js"></script>
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
**googlemap.js**
|
130
|
+
|
131
|
+
```javascript
|
132
|
+
|
133
|
+
(function($) {
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
/*
|
138
|
+
|
139
|
+
* new_map
|
140
|
+
|
141
|
+
*
|
142
|
+
|
143
|
+
* This function will render a Google Map onto the selected jQuery element
|
144
|
+
|
145
|
+
*
|
146
|
+
|
147
|
+
* @type function
|
148
|
+
|
149
|
+
* @date 8/11/2013
|
150
|
+
|
151
|
+
* @since 4.3.0
|
152
|
+
|
153
|
+
*
|
154
|
+
|
155
|
+
* @param $el (jQuery element)
|
156
|
+
|
157
|
+
* @return n/a
|
158
|
+
|
159
|
+
*/
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
function new_map( $el ) {
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
// var
|
168
|
+
|
169
|
+
var $markers = $el.find('.marker');
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
// vars
|
176
|
+
|
177
|
+
var args = {
|
178
|
+
|
179
|
+
zoom : 16,
|
180
|
+
|
181
|
+
center : new google.maps.LatLng(0, 0),
|
182
|
+
|
183
|
+
mapTypeId : google.maps.MapTypeId.ROADMAP
|
184
|
+
|
185
|
+
};
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
// create map
|
192
|
+
|
193
|
+
var map = new google.maps.Map( $el[0], args);
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
// add a markers reference
|
200
|
+
|
201
|
+
map.markers = [];
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
// add markers
|
208
|
+
|
209
|
+
$markers.each(function(){
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
add_marker( $(this), map );
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
});
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
// center map
|
224
|
+
|
225
|
+
center_map( map );
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
// return
|
232
|
+
|
233
|
+
return map;
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
/*
|
242
|
+
|
243
|
+
* add_marker
|
244
|
+
|
245
|
+
*
|
246
|
+
|
247
|
+
* This function will add a marker to the selected Google Map
|
248
|
+
|
249
|
+
*
|
250
|
+
|
251
|
+
* @type function
|
252
|
+
|
253
|
+
* @date 8/11/2013
|
254
|
+
|
255
|
+
* @since 4.3.0
|
256
|
+
|
257
|
+
*
|
258
|
+
|
259
|
+
* @param $marker (jQuery element)
|
260
|
+
|
261
|
+
* @param map (Google Map object)
|
262
|
+
|
263
|
+
* @return n/a
|
264
|
+
|
265
|
+
*/
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
function add_marker( $marker, map ) {
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
// var
|
274
|
+
|
275
|
+
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
// create marker
|
280
|
+
|
281
|
+
var marker = new google.maps.Marker({
|
282
|
+
|
283
|
+
position : latlng,
|
284
|
+
|
285
|
+
map : map
|
286
|
+
|
287
|
+
});
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
// add to array
|
292
|
+
|
293
|
+
map.markers.push( marker );
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
// if marker contains HTML, add it to an infoWindow
|
298
|
+
|
299
|
+
if( $marker.html() )
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
// create info window
|
304
|
+
|
305
|
+
var infowindow = new google.maps.InfoWindow({
|
306
|
+
|
307
|
+
content : $marker.html()
|
308
|
+
|
309
|
+
});
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
// show info window when marker is clicked
|
314
|
+
|
315
|
+
google.maps.event.addListener(marker, 'click', function() {
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
infowindow.open( map, marker );
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
});
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
/*
|
334
|
+
|
335
|
+
* center_map
|
336
|
+
|
337
|
+
*
|
338
|
+
|
339
|
+
* This function will center the map, showing all markers attached to this map
|
340
|
+
|
341
|
+
*
|
342
|
+
|
343
|
+
* @type function
|
344
|
+
|
345
|
+
* @date 8/11/2013
|
346
|
+
|
347
|
+
* @since 4.3.0
|
348
|
+
|
349
|
+
*
|
350
|
+
|
351
|
+
* @param map (Google Map object)
|
352
|
+
|
353
|
+
* @return n/a
|
354
|
+
|
355
|
+
*/
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
function center_map( map ) {
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
// vars
|
364
|
+
|
365
|
+
var bounds = new google.maps.LatLngBounds();
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
// loop through all markers and create bounds
|
370
|
+
|
371
|
+
$.each( map.markers, function( i, marker ){
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
bounds.extend( latlng );
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
});
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
// only 1 marker?
|
388
|
+
|
389
|
+
if( map.markers.length == 1 )
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
// set center of map
|
394
|
+
|
395
|
+
map.setCenter( bounds.getCenter() );
|
396
|
+
|
397
|
+
map.setZoom( 16 );
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
else
|
402
|
+
|
403
|
+
{
|
404
|
+
|
405
|
+
// fit to bounds
|
406
|
+
|
407
|
+
map.fitBounds( bounds );
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
/*
|
418
|
+
|
419
|
+
* document ready
|
420
|
+
|
421
|
+
*
|
422
|
+
|
423
|
+
* This function will render each map when the document is ready (page has loaded)
|
424
|
+
|
425
|
+
*
|
426
|
+
|
427
|
+
* @type function
|
428
|
+
|
429
|
+
* @date 8/11/2013
|
430
|
+
|
431
|
+
* @since 5.0.0
|
432
|
+
|
433
|
+
*
|
434
|
+
|
435
|
+
* @param n/a
|
436
|
+
|
437
|
+
* @return n/a
|
438
|
+
|
439
|
+
*/
|
440
|
+
|
441
|
+
// global var
|
442
|
+
|
443
|
+
var map = null;
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
$(document).ready(function(){
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
$('.acf-map').each(function(){
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
// create map
|
456
|
+
|
457
|
+
map = new_map( $(this) );
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
});
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
});
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
})(jQuery);
|
470
|
+
|
471
|
+
```
|
1
出力したHTMLを追記いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,3 +39,71 @@
|
|
39
39
|
コンソールで確認したところエラーもなく、ソースを見てもGoogleMapの箇所だけすっぽり抜けています。
|
40
40
|
|
41
41
|
WordpressやGoogleMapのカスタマイズに詳しい方アドバイスをお願いいたします。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
追記です
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```HTML
|
52
|
+
|
53
|
+
<section class="container">
|
54
|
+
|
55
|
+
<!-- map -->
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
<div class="list_wrap">
|
60
|
+
|
61
|
+
<ul id="taxid_10">
|
62
|
+
|
63
|
+
<li>
|
64
|
+
|
65
|
+
<div class="postthmub"> <a href="#"><img src="/wp-content/uploads/2016/11/s_DSC_3471-300x200.jpg" alt="137" width="" height=""></a> </div>
|
66
|
+
|
67
|
+
<dl class="postItem">
|
68
|
+
|
69
|
+
<dt><a href="#">土地01</a></dt>
|
70
|
+
|
71
|
+
<dd></dd>
|
72
|
+
|
73
|
+
</dl>
|
74
|
+
|
75
|
+
</li>
|
76
|
+
|
77
|
+
<li>
|
78
|
+
|
79
|
+
<div class="postthmub"> <a href="#"><img src="/wp-content/uploads/2016/11/s_DSC_3471-300x200.jpg" alt="137" width="" height=""></a> </div>
|
80
|
+
|
81
|
+
<dl class="postItem">
|
82
|
+
|
83
|
+
<dt><a href="#">土地02</a></dt>
|
84
|
+
|
85
|
+
<dd></dd>
|
86
|
+
|
87
|
+
</dl>
|
88
|
+
|
89
|
+
</li>
|
90
|
+
|
91
|
+
</ul>
|
92
|
+
|
93
|
+
</div>
|
94
|
+
|
95
|
+
<!-- end .list_wrap -->
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
</section>
|
100
|
+
|
101
|
+
<!-- end container -->
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
2行目の`<!-- map -->`の部分にコードを入れています。
|