Javascript 谷歌地图API信息窗口
我现在有点问题,我已经为我的地图创建了一个自定义样式,但我希望它显示一个信息窗口。我确实将它设置为实际的lat和long,但它似乎没有以某种方式出现 谁能帮我一下吗Javascript 谷歌地图API信息窗口,javascript,api,google-maps,Javascript,Api,Google Maps,我现在有点问题,我已经为我的地图创建了一个自定义样式,但我希望它显示一个信息窗口。我确实将它设置为实际的lat和long,但它似乎没有以某种方式出现 谁能帮我一下吗 //Google maps Javascript, APi V3 var map; var sydney = new google.maps.LatLng(-33.866652,151.063670); var MY_MAPTYPE_ID = 'custom_style'; fun
//Google maps Javascript, APi V3
var map;
var sydney = new google.maps.LatLng(-33.866652,151.063670);
var MY_MAPTYPE_ID = 'custom_style';
function initialize() {
var featureOpts = [
{
stylers: [
{ hue: '#fdc43d' },
]
}
];
var mapOptions = {
zoom: 13,
center: sydney,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: sydney,
map: map,
title: 'Uluru (Ayers Rock)'
});
var styledMapOptions = {
name: 'Custom Style'
};
var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
map.mapTypes.set(MY_MAPTYPE_ID, customMapType);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
//谷歌地图Javascript,APi V3
var映射;
var sydney=new google.maps.LatLng(-33.866652151.063670);
var MY_MAPTYPE_ID='custom_style';
函数初始化(){
变量特性选项=[
{
样式:[
{色调:'#fdc43d'},
]
}
];
变量映射选项={
缩放:13,
中心:悉尼,
mapTypeControlOptions:{
MapTypeId:[google.maps.MapTypeId.ROADMAP,我的地图类型]
},
mapTypeId:MY_MAPTYPE_ID
};
var contentString=''+
''+
''+
“乌鲁鲁”+
''+
“Uluru,也称为艾尔斯岩,是一个大型的”+
“南部的砂岩岩层”+
“澳大利亚中部的北领地。它位于335公里(208英里)处”+
“最近的大城镇艾丽斯·斯普林斯西南部;450 ;公里”+
"(280)英里(约160英里)的公路,卡塔特朱塔和乌鲁鲁是两个主要城市"+
“乌卢鲁-卡塔朱塔国家公园的特征。乌卢鲁是”+
“对Pitjantjatjara和Yankunytjatjara来说是神圣的”+
“该地区的土著居民。这里有许多泉水和水坑,”+
“岩洞和古画。乌鲁鲁被列为世界”+
“遗产地。”+
“归属:乌卢鲁,”+
(上次访问日期为2009年6月22日)。'+
''+
'';
var infowindow=new google.maps.infowindow({
内容:contentString
});
var marker=new google.maps.marker({
职位:悉尼,
地图:地图,
标题:“乌卢鲁(艾尔斯岩)”
});
var styledMapOptions={
名称:“自定义样式”
};
var customMapType=new google.maps.StyledMapType(featureOpts,styledMapOptions);
map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
map.mapTypes.set(MY\u MAPTYPE\u ID,customMapType);
google.maps.event.addListener(标记'click',函数(){
信息窗口。打开(地图、标记);
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
}))
谢谢 当您单击标记时,信息窗口当前将打开,但标记没有出现,因为在您创建标记时,地图尚未初始化 固定代码:
//Google maps Javascript, APi V3
var map;
var sydney = new google.maps.LatLng(-33.866652,151.063670);
var MY_MAPTYPE_ID = 'custom_style';
function initialize() {
var featureOpts = [
{
stylers: [
{ hue: '#fdc43d' },
]
}
];
var mapOptions = {
zoom: 13,
center: sydney,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
//create the map before the marker
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: sydney,
map: map,
title: 'Uluru (Ayers Rock)'
});
var styledMapOptions = {
name: 'Custom Style'
};
var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);
map.mapTypes.set(MY_MAPTYPE_ID, customMapType);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
//triggering the marker-click will open the InfoWindow
google.maps.event.trigger(marker,'click')
}
google.maps.event.addDomListener(window, 'load', initialize);
//谷歌地图Javascript,APi V3
var映射;
var sydney=new google.maps.LatLng(-33.866652151.063670);
var MY_MAPTYPE_ID='custom_style';
函数初始化(){
变量特性选项=[
{
样式:[
{色调:'#fdc43d'},
]
}
];
变量映射选项={
缩放:13,
中心:悉尼,
mapTypeControlOptions:{
MapTypeId:[google.maps.MapTypeId.ROADMAP,我的地图类型]
},
mapTypeId:MY_MAPTYPE_ID
};
var contentString=''+
''+
''+
“乌鲁鲁”+
''+
“Uluru,也称为艾尔斯岩,是一个大型的”+
“南部的砂岩岩层”+
“澳大利亚中部的北领地。它位于335公里(208英里)处”+
“最近的大城镇艾丽斯·斯普林斯西南部;450 ;公里”+
"(280)英里(约160英里)的公路,卡塔特朱塔和乌鲁鲁是两个主要城市"+
“乌卢鲁-卡塔朱塔国家公园的特征。乌卢鲁是”+
“对Pitjantjatjara和Yankunytjatjara来说是神圣的”+
“该地区的土著居民。这里有许多泉水和水坑,”+
“岩洞和古画。乌鲁鲁被列为世界”+
“遗产地。”+
“归属:乌卢鲁,”+
(上次访问日期为2009年6月22日)。'+
''+
'';
var infowindow=new google.maps.infowindow({
内容:contentString
});
//在标记之前创建地图
map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:悉尼,
地图:地图,
标题:“乌卢鲁(艾尔斯岩)”
});
var styledMapOptions={
名称:“自定义样式”
};
var customMapType=new google.maps.StyledMapType(featureOpts,styledMapOptions);
map.mapTypes.set(MY\u MAPTYPE\u ID,customMapType);
google.maps.event.addListener(标记'click',函数(){
信息窗口。打开(地图、标记);
});
//触发标记单击将打开信息窗口
google.maps.event.trigger(标记,'click')
}
google.maps.event.addDomListener(窗口“加载”,初始化);
回答得很好,谢谢。。我知道这是因为初始顺序。我猜就是找不到合适的。再次感谢。