teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

2018/04/14 21:40

投稿

memu2
memu2

スコア16

title CHANGED
File without changes
body CHANGED
@@ -124,4 +124,5 @@
124
124
  このサイトを参考にjsonへの書き込み処理と読み込み処理を記述しました。
125
125
  [http://sanvarie.hatenablog.com/entry/2015/12/06/104506](http://sanvarie.hatenablog.com/entry/2015/12/06/104506)
126
126
 
127
- ,
127
+ 追記3:
128
+ ごめんやん

2

jsonコードを追記

2018/04/14 21:39

投稿

memu2
memu2

スコア16

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  ちなみに当該htmlファイルとjquery、javascript、jsonファイルはすべて同一ディレクトリ内に置いてあります。
15
15
 
16
- 追記
16
+ 追記1:html
17
17
  ```html
18
18
  <!DOCTYPE html>
19
19
  <html>
@@ -97,4 +97,31 @@
97
97
  </form>
98
98
  </body>
99
99
  </html>
100
- ```
100
+ ```
101
+ 追記2:json
102
+ ```json
103
+ [
104
+ {
105
+ "body": "\u3002",
106
+ "lat": 35.668416,
107
+ "lng": 139.728201,
108
+ "name": "sample1",
109
+ },
110
+ {
111
+ "body": "\u3002",
112
+ "lat": 35.868416,
113
+ "lng": 139.728201,
114
+ "name": "sample2",
115
+ },
116
+ {
117
+ "body": "\u4e43\u3002",
118
+ "lat": 35.674565,
119
+ "lng": 139.71699,
120
+ "name": "sample3",
121
+ }
122
+ ]
123
+ ```
124
+ このサイトを参考にjsonへの書き込み処理と読み込み処理を記述しました。
125
+ [http://sanvarie.hatenablog.com/entry/2015/12/06/104506](http://sanvarie.hatenablog.com/entry/2015/12/06/104506)
126
+
127
+ ,

1

htmlのコードを追加

2018/04/14 06:40

投稿

memu2
memu2

スコア16

title CHANGED
File without changes
body CHANGED
@@ -11,4 +11,90 @@
11
11
  これらのことを踏まえると、おそらくサーバー内の外部ファイルをhtmlから読み込む際に問題が発生し、エラーの原因になっていると考えられるのですが、全く改善方法が分かりません。
12
12
  これらの原因にどなたか心当たりのある方はいらっしゃるでしょうか?
13
13
 
14
- ちなみに当該htmlファイルとjquery、javascript、jsonファイルはすべて同一ディレクトリ内に置いてあります。
14
+ ちなみに当該htmlファイルとjquery、javascript、jsonファイルはすべて同一ディレクトリ内に置いてあります。
15
+
16
+ 追記
17
+ ```html
18
+ <!DOCTYPE html>
19
+ <html>
20
+ <head>
21
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
22
+ <meta charset="utf-8">
23
+ <title>Info window with <code>maxWidth</code></title>
24
+ <style>
25
+ /* Always set the map height explicitly to define the size of the div
26
+ * element that contains the map. */
27
+ #map {
28
+ height: 100%;
29
+ }
30
+ /* Optional: Makes the sample page fill the window. */
31
+ html, body {
32
+ height: 100%;
33
+ margin: 0;
34
+ padding: 0;
35
+ }
36
+ </style>
37
+ <script src="https://maps.googleapis.com/maps/api/js?key=MY_APIKEY">
38
+ </script>
39
+ <script>
40
+ function initMap(){
41
+ // Map options
42
+ var options = {
43
+ zoom:5,
44
+ center:{lat:42.999988, lng:-71.888888}
45
+ };
46
+
47
+ // Add map
48
+ var map = new google.maps.Map(document.getElementById('map'), options);
49
+ }
50
+
51
+
52
+ function loadJson_and_addMarkers(){
53
+ var json = [];
54
+ $(function(){
55
+ $.getJSON("new_data.json" , function(data) {
56
+ json = data;
57
+ });
58
+ });
59
+ for(var i = 0;i < json.length;i++){
60
+ addMarker(json[i]);
61
+ }
62
+ }
63
+
64
+
65
+
66
+
67
+ function addMarker(json){
68
+ var marker = new google.maps.Marker({
69
+ positions:{lat:json.lat, lng:json.lng},
70
+ map:map
71
+ });
72
+
73
+ var content = '<h1>' + json.name + '</h1>'+
74
+ '<div id="bodycontent">' + json.body + '</div>';
75
+
76
+ var infowindow = new google.maps.InfoWindow({
77
+ content:content
78
+ });
79
+
80
+ marker.addListener('click', function(){
81
+ infowindow.open(map, marker);
82
+ });
83
+ }
84
+
85
+
86
+ </script>
87
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript">
88
+ </script>
89
+ </head>
90
+
91
+ <body onload="initMap()">
92
+ <div id="map"></div>
93
+ <form>
94
+ <p>
95
+ <input type="button" id="btn" value="make Markers" onclick="loadJson_and_addMarkers()" />
96
+ </p>
97
+ </form>
98
+ </body>
99
+ </html>
100
+ ```