我有一个只有一个标记和一个infoBubble的谷歌地图。单击标记时会出现信息气泡。问题是信息气泡直接出现在标记上,而不是在它上面。


这是代码,我使用的是地理编码器,因为我只有命名的地址:
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myOptions = {
zoom: 14,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
//i am using simple InfoBubble initialization
var infoBubble = new InfoBubble(
{
map: map,
content: "<h2>"+name+"</h2><div>"+street+"</div><div>"+city+", "+zip+"</div>"
});
google.maps.event.addListener(marker, 'click', function(e) {
infoBubble.open(map,marker);
});
}
});你知道为什么会发生这种事吗?
发布于 2013-02-27 20:16:21
创建infoBubble时忽略map-option。
发布于 2013-09-08 13:12:52
我发现下面的代码片段中的http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html,try非常方便。
var map, infoBubble;
function init() {
var mapCenter = new google.maps.LatLng(-35.397, 150.644);
map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: mapCenter,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(-35, 150),
draggable: true
});
infoBubble = new InfoBubble({
maxWidth: 300
});
infoBubble.open(map, marker);
infoBubble.setContent('This is a sample content') //Please set your content here.
google.maps.event.addListener(marker, 'click', function() {
if (!infoBubble.isOpen()) {
infoBubble.open(map, marker);
}
});
}
google.maps.event.addDomListener(window, 'load', init);
}
[1]: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.htmlhttps://stackoverflow.com/questions/15111128
复制相似问题