マップ マーカーにクリック イベントを設定して情報ウィンドウを作成しています。住所をジオコーディングして情報ウィンドウ内に表示しようとしています。
click: function(marker) {
pantoUser(lati,longi,i);
addInfoWindow(lati,longi,name,datestring);
}
私はほとんどそれが次のように機能しています:
function addInfoWindow(lati,longi,name,datestring)
{
// get address
getAddress(lati,longi);
// create infowindow
$('#dispatcher').gmap3(
{ action: 'addInfoWindow',
latLng: [lati, longi],
infowindow:{
options:{
content: name
},
events:{
closeclick: function(infowindow, event){
//alert('closing : ' + $(this).attr('id') + ' : ' + infowindow.getContent());
}
},
apply:[
{ action:'setContent',
args:[
'<span class="infowindow">' + name + '<br />' + content + '<br />' + datestring + '<span>'
]
}
]
}
}
);
}
次に、アドレスの取得部分:
function getAddress(lati,longi)
{
$("#dispatcher").gmap3({
action:'getAddress',
latLng: [lati, longi],
callback:function(results){
content = results && results[1] ? results && results[1].formatted_address : 'No Address';
return content;
}
});
}
問題は、ジオコーディングされた住所が常に 1 マーカー クリック遅れることです。たとえば、ロンドンのマーカーをクリックしても何も起こりません。もう一度クリックすると、住所が記載された情報ウィンドウが表示されます。次に、マンチェスターのマーカーをクリックすると、まだロンドンの住所が表示されます。次に、リバプールのマーカーをクリックすると、マンチェスターの住所が表示されます。等々。
誰でもバグを見つけることができますか?
SEAN からの更新された実用的なソリューション コールバックに情報ウィンドウ コードを追加しました
function addInfoWindow(lati,longi,name,datestring)
{
// get address
$("#dispatcher").gmap3({
action:'getAddress',
latLng: [lati, longi],
callback:function(results){
content = results && results[1] ? results && results[1].formatted_address : 'No Address';
// create infowindow
$('#dispatcher').gmap3(
{ action: 'addInfoWindow',
latLng: [lati, longi],
infowindow:{
options:{
content: name
},
events:{
closeclick: function(infowindow, event){
//alert('closing : ' + $(this).attr('id') + ' : ' + infowindow.getContent());
}
},
apply:[
{ action:'setContent',
args:[
'<span class="infowindow">' + name + '<br />' + content + '<br />' + datestring + '<span>'
]
}
]
}
}
);
} // end callback
});
}