首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >infoBubble错误定位在标记上

infoBubble错误定位在标记上
EN

Stack Overflow用户
提问于 2013-02-27 19:38:04
回答 2查看 733关注 0票数 1

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

这是代码,我使用的是地理编码器,因为我只有命名的地址:

代码语言:javascript
复制
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);
            });

        }
    });

你知道为什么会发生这种事吗?

EN

回答 2

Stack Overflow用户

发布于 2013-02-27 20:16:21

创建infoBubble时忽略map-option。

票数 2
EN

Stack Overflow用户

发布于 2013-09-08 13:12:52

我发现下面的代码片段中的http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html,try非常方便。

代码语言:javascript
复制
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.html
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15111128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档