Javascript 我正在尝试将标记群集添加到我的谷歌地图脚本中
我正试图将var markerCluster添加到我的google地图脚本中,但在为我的标记创建新布局后,我无法找到适合var markerCluster的位置,而不会导致我的地图或标记不显示 我已经尝试将var-markerCluster添加到脚本的大部分区域。我现在开始怀疑我是否必须完全改变布局Javascript 我正在尝试将标记群集添加到我的谷歌地图脚本中,javascript,google-maps,markerclusterer,Javascript,Google Maps,Markerclusterer,我正试图将var markerCluster添加到我的google地图脚本中,但在为我的标记创建新布局后,我无法找到适合var markerCluster的位置,而不会导致我的地图或标记不显示 我已经尝试将var-markerCluster添加到脚本的大部分区域。我现在开始怀疑我是否必须完全改变布局 var map; var InforObj = []; // Add a marker clusterer to manage the markers. var markerCluster = ne
var map;
var InforObj = [];
// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, { imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });
var centerCords = {
lat: 16.058324,
lng: 108.277000
};
var markersOnMap = [{
placeName: ' <b>Ho-Chi-Minh City</b> <br>' +
'Ho Chi Minh City (commonly known as Saigon) is a city in southern Vietnam. <br>' +
'Famous for the pivotal role it played in' +
'the Vietnam War. Its also known for its French colonial landmarks,' +
'including Notre-Dame Cathedral, made entirely of materials imported from France,' +
'and the 19th-century Central Post Office. Food stalls line the city’s streets,' +
'especially around bustling Bến Thành Market.',
LatLng: [{
lat: 10.775844,
lng: 106.701756
}]
},
{
placeName: "<b>Grand Mercure Danang (Da Nang City)</b> <br>" +
'<b>Address:</b> Zone of the Villas of Green Island, Lot A1, Đà Nẵng 084511, Vietnam. <br>'+
'<b>Five Star Hotel</b> - ☆☆☆☆☆ ' ,
icon: 'pin.png',
LatLng: [{
lat: 16.048297,
lng: 108.226951
}]
},
{
placeName: '<b>Da Nang City</b> <br>' +
'Da Nang is a coastal city in central Vietnam known for its sandy beaches and history' +
'as a French colonial port. Its a popular base for visiting the inland <b>Bà Nà</b> hills' +
'to the west of the city. Here the hillside <b>Hải Vân</b> Pass has views of Da Nang Bay' +
'and the Marble Mountains. These 5 limestone outcrops are topped with pagodas and hide' +
'caves containing Buddhist shrines.',
LatLng: [{
lat: 16.068000,
lng: 108.212000
}]
},
{
placeName: "<b>Dalat Hôtel du Parc (Dalat City)</b> <br>" +
'<b>Address:</b> 15 Đường Trần Phú, Phường 3, Thành phố Đà Lạt, Lâm Đồng, Vietnam',
icon: 'pin.png',
LatLng: [{
lat: 11.9367,
lng: 108.4390
}]
},
{
placeName: "<b>Nhà gỗ - The Wooden House Restaurant (Dalat City)</b> <br>" +
'<b>Address:</b> 26 Đường Nguyễn Đình Chiểu, Phường 9, Thành phố Đà Lạt, Lâm Đồng, Vietnam',
icon: 'pin.png',
LatLng: [{
lat: 11.9505,
lng: 108.4582
}]
},
{
placeName: '<b>Dalat City</b> <br>' +
'<b>Đà Lạt</b>, the capital of <b>Lâm Đồng</b> Province in southern Vietnam’s Central Highlands,' +
'is centered around a lake and golf course, and surrounded by hills, pine forests,' +
'lakes and waterfalls. Known as the “City of Eternal Spring” for its distinctive temperate' +
'climate, Đà Lạt was developed as a resort by the French in the early 1900s,' +
'and many reminders of its colonial heritage remain.',
LatLng: [{
lat: 11.936230,
lng: 108.445259
}]
},
{
placeName: "<b>Beaulieu Boutique Hotel (Hue City)</b> <br>" +
'<b>Address:</b> 15 Pham Ngu Lao, Hue, Vietnam',
icon: 'pin.png',
LatLng: [{
lat: 16.4691,
lng: 107.5947
}]
},
{
placeName: "<b>Hanh Restaurant (Hue City)</b> <br>" +
'<b>Address:</b> 11 Đường Phó Đức Chính, Phú Hội, Tp. Huế, Phú Hội, Vietnam',
icon: 'pin.png',
LatLng: [{
lat: 16.4663,
lng: 107.5950
}]
},
{
placeName: '<b>Hue City</b> <br>' +
'Huế is a city in central Vietnam that was the seat of Nguyen Dynasty emperors and the' +
'national capital from 1802 to 1945. A major attraction is its vast,' +
'19th-century <b>Đại Nội Citadel</b>, surrounded by a moat and thick stone walls.' +
'It encompasses the Imperial City, with palaces and shrines;' +
'the Forbidden Purple City (<b>Tử cấm thành</b>), once the emperor’s home;' +
'and a replica of the Royal Theater.',
LatLng: [{
lat: 16.463713,
lng: 107.590866
}]
},
{
placeName: "Vietnam (Hanoi Cooking Centre)",
icon: 'pin.png',
LatLng: [{
lat: 21.054374,
lng: 105.837032
}]
},
{
placeName: "Vietnam (Fortuna Hotel, Hanoi)",
icon: 'pin.png',
LatLng: [{
lat: 21.0215,
lng: 105.8178
}]
},
{
placeName: '<b>Hanoi</b> (<b>Capital City</b>) <br>' +
'is known for its centuries-old architecture and a rich culture with Southeast Asian,' +
'Chinese and French influences. At its heart is the chaotic Old Quarter, where the narrow' +
'streets are roughly arranged by trade. There are many little temples,' +
'including Bach Ma, honoring a legendary horse,' +
'plus Đồng Xuân Market, selling household goods and street food.',
LatLng: [{
lat: 21.027763,
lng: 105.834160
}]
}
];
window.onload = function() {
initMap();
};
function addMarker() {
for (var i = 0; i < markersOnMap.length; i++) {
var contentString = '<div id="content"><p>' + markersOnMap[i].placeName +
'</p></div>';
const marker = new google.maps.Marker({
position: markersOnMap[i].LatLng[0],
map: map
});
const infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 200
});
marker.addListener('click', function() {
closeOtherInfo();
infowindow.open(marker.get('map'), marker);
InforObj[0] = infowindow;
});
marker.addListener('mouseover', function() {
closeOtherInfo();
infowindow.open(marker.get('map'), marker);
InforObj[0] = infowindow;
});
}
}
function closeOtherInfo() {
if (InforObj.length > 0) {
/* detach the info-window from the marker ... undocumented in the API docs */
InforObj[0].set("marker", null);
/* and close it */
InforObj[0].close();
/* blank the array */
InforObj.length = 0;
}
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: centerCords
});
addMarker();
}
var映射;
var InforObj=[];
//添加标记群集器以管理标记。
var markerCluster=newmarkerclusterer(映射,标记,{imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });
var中心线={
纬度:16.058324,
液化天然气:108.277000
};
var markersOnMap=[{
地名:“胡志明市
”+
胡志明市(俗称西贡)是越南南部的一座城市。
'+
“以其在其中发挥的关键作用而闻名”+
越南战争。它也以其法国殖民地标而闻名+
“包括圣母院大教堂,全部由从法国进口的材料制成,”+
还有19世纪的中央邮政局。城市街道两旁都是食品摊+
尤其是在繁华的B区ế新罕布什尔州市场。”,
板条:[{
纬度:10.775844,
液化天然气:106.701756
}]
},
{
地名:“岘港美爵酒店(岘港市)
”+
'地址:青洲别墅区,A1地块,西贡ẵng 084511,越南。
'
“五星级酒店-☆☆☆☆☆ ' ,
图标:“pin.png”,
板条:[{
纬度:16.048297,
液化天然气:108.226951
}]
},
{
地名:“岘港市
”+
“岘港是越南中部的一个沿海城市,以其沙滩和历史而闻名”+
“作为法国殖民地的港口,它是游览内陆BáNáhills的热门基地”+
“在城市的西面。这里是山坡Hải V–n Pass可以看到岘港湾的景色+
“还有大理石山。这5个石灰岩露头顶部有宝塔和兽皮”+
“藏有佛教神殿的洞穴”,
板条:[{
拉丁美洲:16.068000,
液化天然气:108.212000
}]
},
{
地名:“达拉特公园酒店(达拉特市)
”+
“地址:15Đư”ờng Trầnú,Pường 3,Thánh phố Đa Lạt、 L–mĐồ越南",,
图标:“pin.png”,
板条:[{
拉脱维亚:11.9367,
液化天然气:108.4390
}]
},
{
地名:“Nhágỗ - 木屋餐厅(达拉特市)
“+
“地址:26Đư”ờ吴恩圭ễ新罕布什尔州ểu、 Phường 9,Thánh phố Đa Lạt、 L–mĐồ越南",,
图标:“pin.png”,
板条:[{
纬度:11.9505,
液化天然气:108.4582
}]
},
{
地名:“达拉特市
”+
ĐĐLạt、 拉穆的首都ồ位于越南中部高地南部的ng省+
“以湖泊和高尔夫球场为中心,四周群山环绕,松林环绕,”+
湖泊和瀑布。因其独特的温带气候而被称为“永恒的春天之城”+
“气候ạ它在20世纪初被法国人开发成一个旅游胜地+
“许多关于其殖民地遗产的记忆依然存在。”,
板条:[{
纬度:11.936230,
液化天然气:108.445259
}]
},
{
地名:“博来精品酒店(顺化市)
”+
“地址:越南顺化市范Ngu-Lao 15号”,
图标:“pin.png”,
板条:[{
拉脱维亚:16.4691,
液化天然气:107.5947
}]
},
{
地名:“汉餐厅(顺化市)
”+
“地址:11Đư”ờ吴伯雄ứcènh,PhúHội、 胡总领事ế, 普赫ội、 越南",,
图标:“pin.png”,
板条:[{
拉脱维亚:16.4663,
液化天然气:107.5950
}]
},
{
地名:“顺化市
”+
"胡ế 是越南中部的一座城市,曾是阮王朝皇帝和+
“从1802年到1945年的首都。一个主要的吸引力是它的广阔,”他说+
“19世纪”ạ我ộ我喜欢城堡,四周有护城河和厚厚的石墙。”+
“它包括皇城,有宫殿和神殿;”+
紫禁城ử Cấ曾经是皇帝的家+
“还有皇家剧院的复制品。”,
板条:[{
纬度:16.463713,
液化天然气:107.590866
}]
},
{
地名:“越南(河内烹饪中心)”,
图标:“pin.png”,
板条:[{
纬度:21.054374,
液化天然气:105.837032
}]
},
{
地名:“越南(河内福图纳酒店)”,
图标:“pin.png”,
板条:[{
拉脱维亚:21.0215,
液化天然气:105.8178
}]
},
{
地名:“河内(首都)
”+
“以其具有数百年历史的建筑和丰富的东南亚文化而闻名,”他说+
中国和法国的影响。它的核心是混乱的老城区,狭窄的+
“街道大致按行业排列,有许多小寺庙,”+
“包括巴赫马,纪念一匹传奇马”+
"加Đồ吴旭恩市场,出售家庭用品和街头食品,
板条:[{
纬度:21.027763,
液化天然气:105.834160
}]
}
];
window.onload=函数(){
initMap();
};
函数addMarker(){
对于(变量i=0;i”;
const marker=new google.maps.marker({
位置:markersOnMap[i]。LatLng[0],
地图:地图
});
欺骗
function addMarker() {
var markers = [];
for (var i = 0; i < markersOnMap.length; i++) {
var contentString = '<div id="content"><p>' + markersOnMap[i].placeName +
'</p></div>';
const marker = new google.maps.Marker({
position: markersOnMap[i].LatLng[0],
map: map
});
const infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 200
});
marker.addListener('click', function() {
closeOtherInfo();
infowindow.open(marker.get('map'), marker);
InforObj[0] = infowindow;
});
marker.addListener('mouseover', function() {
closeOtherInfo();
infowindow.open(marker.get('map'), marker);
InforObj[0] = infowindow;
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers, {
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
}