回答編集履歴

5

修正

2016/02/21 15:59

投稿

fagai
fagai

スコア2158

test CHANGED
@@ -20,15 +20,15 @@
20
20
 
21
21
  var contentString;
22
22
 
23
- var infoWindow
23
+ var infowindow;
24
24
 
25
25
  for(var i = 0; i < shops.length; i++) {
26
26
 
27
27
  contentString = shops[i].title;
28
28
 
29
- infoWindow = new google.maps.InfoWindow({ content: contentString });
29
+ infowindow = new google.maps.InfoWindow({ content: contentString });
30
30
 
31
- google.maps.event.addListener(shops[i], 'click', function() { infoWindow.open(map,shops[i]); });
31
+ google.maps.event.addListener(shops[i], 'click', function() { infowindow.open(map,shops[i]); });
32
32
 
33
33
  }
34
34
 
@@ -52,9 +52,9 @@
52
52
 
53
53
  var contentString = shops[i].title;
54
54
 
55
- var infoWindow = new google.maps.InfoWindow({ content: contentString });
55
+ var infowindow = new google.maps.InfoWindow({ content: contentString });
56
56
 
57
- google.maps.event.addListener(shops[i], 'click', function() { infoWindow.open(map,shops[i]); });
57
+ google.maps.event.addListener(shops[i], 'click', function() { infowindow.open(map,shops[i]); });
58
58
 
59
59
  })();
60
60
 

4

修正

2016/02/21 15:59

投稿

fagai
fagai

スコア2158

test CHANGED
@@ -16,13 +16,19 @@
16
16
 
17
17
 
18
18
 
19
+
20
+
21
+ var contentString;
22
+
23
+ var infoWindow
24
+
19
25
  for(var i = 0; i < shops.length; i++) {
20
26
 
21
- var contentString = shops[i].title;
27
+ contentString = shops[i].title;
22
28
 
23
- var infowindow = new google.maps.InfoWindow({ content: contentString });
29
+ infoWindow = new google.maps.InfoWindow({ content: contentString });
24
30
 
25
- google.maps.event.addListener(shops[i], 'click', function() { infowindow.open(map,shops[i]); });
31
+ google.maps.event.addListener(shops[i], 'click', function() { infoWindow.open(map,shops[i]); });
26
32
 
27
33
  }
28
34
 
@@ -31,3 +37,27 @@
31
37
 
32
38
 
33
39
  このように配列にすることで、複数のshopが増えても対応できると思います。
40
+
41
+
42
+
43
+ 追記
44
+
45
+ もしかしたら修正部分は以下の形式でも行けるかもです。
46
+
47
+ ```
48
+
49
+ for(var i = 0; i < shops.length; i++) {
50
+
51
+ (function(){
52
+
53
+ var contentString = shops[i].title;
54
+
55
+ var infoWindow = new google.maps.InfoWindow({ content: contentString });
56
+
57
+ google.maps.event.addListener(shops[i], 'click', function() { infoWindow.open(map,shops[i]); });
58
+
59
+ })();
60
+
61
+ }
62
+
63
+ ```

3

ソース修正

2016/02/21 15:55

投稿

fagai
fagai

スコア2158

test CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
 
10
10
 
11
- shops[] = new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon1.png', title: '場所1' });
11
+ shops.push(new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon1.png', title: '場所1' }));
12
12
 
13
- shops[] = new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon1.png', title: '場所2' });
13
+ shops.push(new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon1.png', title: '場所2' }));
14
14
 
15
15
  // 省略...
16
16
 

2

修正

2016/02/21 15:07

投稿

fagai
fagai

スコア2158

test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  shops[] = new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon1.png', title: '場所2' });
14
14
 
15
- ...
15
+ // 省略...
16
16
 
17
17
 
18
18
 

1

修正

2016/02/21 13:32

投稿

fagai
fagai

スコア2158

test CHANGED
@@ -1,4 +1,4 @@
1
- shop1,shop2のようにする必要がなければ以下の様な対応方法があると思います。
1
+ shop1,shop2のような変数名にする必要がなければ以下の様な対応方法があると思います。
2
2
 
3
3
 
4
4