良い一日!InfoBubble がリスナーを持つことができるかどうかを尋ねたいだけです。InfoBubble のテキストを div に挿入し、そこに onclick コマンドを挿入しようとしましたが、何も起こりません。
前もって感謝します。ところで、私は現在 Android アプリケーションを開発しており、webview を使用してマップを表示しています。
良い一日!InfoBubble がリスナーを持つことができるかどうかを尋ねたいだけです。InfoBubble のテキストを div に挿入し、そこに onclick コマンドを挿入しようとしましたが、何も起こりません。
前もって感謝します。ところで、私は現在 Android アプリケーションを開発しており、webview を使用してマップを表示しています。
よし、ジェットプロ
JavaScriptを使用して同様のシナリオで行うことは次のとおりです。
/* json data object requires:
data.Id,
data.Lat,
data.Lng,
data.Name,
data.Address,
data.Date
*/
function DisplayMapEvent(data, targetDiv) {
var latlng, options, map, contentString, infowindow, marker;
// setup our variables
latlng = new window.google.maps.LatLng(data.Lat, data.Lng);
options =
{
zoom: 15,
center: latlng,
mapTypeId: window.google.maps.MapTypeId.ROADMAP
};
// create the map inside our map <div> and apply the options
map = new window.google.maps.Map(document.getElementById(targetDiv), options);
map.setOptions(options);
// info to display in the infowindow popup
contentString =
'<div>' +
'<b style="color: #DC6852;">' + data.Name + '</b><br />' +
'Where: ' + data.Address + '<br />' +
'When: ' + data.Date + '<br />' +
'</div>';
// info/marker and popup objects setup
infowindow = new window.google.maps.InfoWindow({
content: contentString
});
marker = new window.google.maps.Marker({
position: latlng,
map: map
});
// add the usual suspect event handlers
window.google.maps.event.trigger(map, 'resize');
// to allow us to repoen a map marker infowindow if closed
window.google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
// open infowindow on map once rendered
infowindow.open(map, marker);
// sit back and wonder at the glory of google maps mow :-)
}
私の場合、json オブジェクトをDisplayMapEvent
関数に渡していますが、これを独自の要件に合わせて変更することもできます。この関数は、マップに新しいマーカーを追加したいときにいつでも呼び出されるため、必要に応じてこのホールセールを持ち上げてリファクタリングできる場合があります。
お役に立てれば。
このようにリスナーを追加します
google.maps.event.addDomListener(infoBubble2.bubble_, 'click', function(){..});
楽しむ!