2017-04-03 10 views
-4

で変数の値にアクセスすることはできません:は、私は、値の配列を持つ配列

var info_tab = [ 
       ["Aaaa", 53.12040528310657, 23.258056640625,1,ikona3], 
       ["Bbbb", 53.09402405506325, 18.0010986328125,2,ikona2], 
      ]; 

ここで私が問題をパラメータとして値を渡す機能でそれを使用するこのセクションである:label: info_tab[i][1]

var markers = locations.map(function(location, i) { 
     return new google.maps.Marker({ 
     position: location, 
     icon: ikona2, 
     label: info_tab[i][1] 
     }); 
    }); 

私はエラーを取得しています:

Uncaught TypeError: Cannot read property '1' of undefined.

はしかし、私はwindow.alert(info_tab[i][1])を経由して、これを表示し、それが示しています良い値です。私のミスはどこですか?

+4

変数 'i'は何を使用し

は、数値を文字列に変換するには? – epascarello

+0

[Array.Map](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/map)ごとに、iは配列の項目 – James

+0

のインデックスです。参照してください.mapループ関数。 – loelsonk

答えて

0

この関数は、53.12040528310657または53.09402405506325のいずれかのマーカーにラベルを追加します。ラベルは文字列である必要があります。 info_tab[i][1].toString()

A marker label is a letter or number that appears inside a marker. The marker image in this section displays a marker label with the letter 'B' on it. You can specify a marker label as either a string or a MarkerLabel object that includes a string and other label properties.

var info_tab = [ 
 
    ["Aaaa", 53.12040528310657, 23.258056640625,1,'icon1'], 
 
    ["Bbbb", 53.09402405506325, 18.0010986328125,2,'icon12'], 
 
]; 
 
      
 
var locations = [ 
 
    {lat: -25.363, lng: 131.044}, 
 
    {lat: -25.363, lng: 131.044}, 
 
] 
 

 
var markers = locations.map(function(location, i) { 
 
    var label = info_tab[i][1]; 
 
    
 
    console.log(label.toString()); // '53.12040528310657' 
 

 
});

関連する問題