コードにエラーがあります
title:inspStates[i].name+ "
"+"total: "+inspStates[i].totalInsp+ "
"+ info;
末尾のセミコロンが間違っています。オブジェクト プロパティを定義していますが、単純な変数は定義していません。2.コードによると、すべてのマーカーが同じ場所に表示されます(もちろん、center
各ループ反復が定義されていない場合)
position: center
たぶん、このようなものがあるはずinspStates[i].position
ですか?
UPD
これが私のコードサンプルです。
var places=[
{
position: new google.maps.LatLng(51.5220975, -0.1702880859375),
name: 'first place'
},
{
position: new google.maps.LatLng(51.51, -0.1714),
name: 'second place'
},
{
position: new google.maps.LatLng(51.52205918460975, -0.17380859375),
name: 'third place'
}
];
for(var i=0, len=places.length; i<len; i++)
{
var marker = new google.maps.Marker({
map: map,
position: places[i].position,
title: places[i].name
});
}
多分それは役に立つでしょう。このコードでは、事前に定義されたタイトルを持つ 3 つのマーカーが表示されています。あなたのコードは私のようなものですか?また、1 つの質問:center
ループの反復ごとにコードが変更される変数です。私はそれについて話しましたが、oyu はコメントしていません。もっと助けが必要な場合は、コード サンプルを投稿していただけますか?