【发布时间】:2012-06-11 19:40:38
【问题描述】:
如何使我的 infoWindows 具有标签内容?我试过这样的事情:
google.maps.event.addListener(this, "domready", function(){ $("#info").tabs() });
*还尝试使用infoWidnwow、infowindow 和iw 代替this 关键字
和
.ready(function(){ $("#info").tabs();});
和
.bind('domready', function(){ $("#info").tabs(); });
这些都不起作用。
创建标记和信息窗口的代码:
$('#map').gmap(mapOptions).bind('init', function(){
$.post('getmarkers.php', function(json){
var theMarkers = json;
$.each(theMarkers, function(i, element) {
$.each(element, function(object, attributes){
$('#map').gmap('addMarker', {
'position': new google.maps.LatLng(parseFloat(attributes.Lat), parseFloat(attributes.Lng)),
'bounds':true } ).click(function(){
$('#map').gmap('openInfoWindow', { 'content':'<div id="info"><ul><li><a href="#tab1">Tab1</li><li><a href="#tab2">Tab2</li></ul><div id="tab1"><h1>'+attributes.productName+'</h1></div><div id="tab2"><h2 style="color: grey"><h1>'+attributes.productPrice+'</h1></div></div>' }, this);
});
});
});
});
});
不知何故我需要告诉这部分:
$('#map').gmap('openInfoWindow', { 'content':'<div id="info"><ul><li><a href="#tab1">Tab1</li><li><a href="#tab2">Tab2</li></ul><div id="tab1"><h1>'+attributes.productName+'</h1></div><div id="tab2"><h2 style="color: grey"><h1>'+attributes.productPrice+'</h1></div></div>' }, this);
标签content 我传递给openInfoWindow。
【问题讨论】:
-
我之前实际上并没有尝试过这样做,但是您不会在创建信息窗口而不是在初始化时提供信息窗口选项卡吗?在初始化时,信息窗口不存在。另外,是否可以有多个信息窗口?如果是这样,那么您使用的 id 将不是唯一的。
-
看起来你来自熟悉 v2 api,其中内置了 infowindow 选项卡。不幸的是,它从未进入 v3 api,所以你必须,正如 Kevin 所说,在打开时创建选项卡信息窗口。如果您不熟悉自己创建选项卡式界面,可以查看类似 jQuery UI 的工具来帮助您。
-
@Kevin B:嗯,不。我使用
opneInfoWindow函数调用了所有这些函数。至于唯一性,你是说我应该尝试使用 CSS 类而不是 id? -
@Adam:不是真的。从第 3 版开始,我一直在使用 Google 地图。我从未接触过 V2 或更低版本。
标签: javascript jquery google-maps google-maps-api-3 jquery-ui-map