谷歌地图v3标记标题属性

发布于 2024-11-25 21:44:18 字数 396 浏览 0 评论 0原文

在我的函数中,我循环遍历状态数组并将标记放置在每个状态的中心。我希望每个标记工具提示显示其特定信息。但是,由于某种原因,当我将鼠标悬停在标记上时,即使我使用 title 属性实例化了标记,工具提示也不会在其中任何一个标记上弹出。

请参阅下面的代码:

mark = new google.maps.Marker({          
        map: map,             
        position: center,
        title:inspStates[i].name+ "<br/>"+"total: "+inspStates[i].totalInsp+ "<br/>"+ info
        });

我的错误是什么?

In my function I am looping through an array of states and placing markers in the center of each state. I want each marker tooltip to display its specific information. However, for some reason when I mouse over the markers a tooltip doesn't popup over any of them even though I instantiated the marker with the title property.

see code below:

mark = new google.maps.Marker({          
        map: map,             
        position: center,
        title:inspStates[i].name+ "<br/>"+"total: "+inspStates[i].totalInsp+ "<br/>"+ info
        });

what is my error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-12-02 21:44:18
  1. 您的代码有错误

    title:inspStates[i].name+ "
    "+"total: "+inspStates[i].totalInsp+ "
    "+ info;

结尾的分号是错误的。您正在定义一个对象属性,但不是简单变量。
2.根据您的代码,所有标记将显示在同一位置(当然,如果每次循环迭代都没有定义center),

position: center

也许应该有类似这样的inspStates[i]。位置

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
    });
}

也许会有帮助。此代码显示了三个带有预定义标题的标记。你的代码和我的一样吗?还有一个问题:代码中的变量 center 是否在每次循环迭代中发生更改。我已经讨论过了,但oyu还没有发表评论。
您能否发布您的代码示例以获得更多帮助?

  1. You have error in your code

    title:inspStates[i].name+ "
    "+"total: "+inspStates[i].totalInsp+ "
    "+ info;

The trailing semicolon is mistaken. You are defining an object property but not the simple variable.
2. According to your code all markers will be shown at same place(Of course, if center is not being defined each loop iteration)

position: center

Maybe there should be something like this inspStates[i].position?

UPD

Here is my code sample.

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
    });
}

Maybe it will be helpfull. Three markers with predifined titles has been shown by this code. Is your code like my? Also one question: Is variable center from your code being changed each loop itaration. I have talked about it but oyu haven't commented it.
Could you please post your code sample to get more help?

自由如风 2024-12-02 21:44:18

我已将disableDefaultUI 设置为true,这显然导致工具提示不显示。当我重新启用它时,所有标记都有一个包含正确信息的工具提示。

I had set the disableDefaultUI to true which apparently caused the tooltips not to be shown. When I reenabled it all the markers had a tooltip with the proper information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文