【发布时间】:2013-08-27 13:49:15
【问题描述】:
我想在一页上有多个谷歌地图。
我有这个代码,但我不知道该怎么做。
必须添加什么?
我想要其他风格相同的地图。
还有一个问题是谷歌地图没有加载完整
谁能帮帮我?
function initialize() {
var styles = [
{
featureType: 'water',
elementType: 'all',
stylers: [
{ hue: '#E6E6E6' },
{ saturation: -100 },
{ lightness: 59 },
{ visibility: 'on' }
]
},{
featureType: 'landscape.natural',
elementType: 'all',
stylers: [
{ hue: '#999999' },
{ saturation: -100 },
{ lightness: -37 },
{ visibility: 'on' }
]
},{
featureType: 'road',
elementType: 'all',
stylers: [
{ hue: '#4C4C4C' },
{ saturation: -100 },
{ lightness: -53 },
{ visibility: 'simplified' }
]
},{
featureType: 'landscape.man_made',
elementType: 'all',
stylers: [
{ hue: '#ffffff' },
{ saturation: -100 },
{ lightness: 100 },
{ visibility: 'on' }
]
},{
featureType: 'road.highway',
elementType: 'all',
stylers: [
{ hue: '#bfbfbf' },
{ saturation: -100 },
{ lightness: 30 },
{ visibility: 'on' }
]
},{
featureType: 'road.arterial',
elementType: 'labels',
stylers: [
{ hue: '#bfbfbf' },
{ saturation: -100 },
{ lightness: -3 },
{ visibility: 'simplified' }
]
},{
featureType: 'road.local',
elementType: 'geometry',
stylers: [
{ hue: '#f1f1f1' },
{ saturation: -100 },
{ lightness: -5 },
{ visibility: 'simplified' }
]
},{
featureType: 'poi',
elementType: 'all',
stylers: [
{ hue: '#e6e6e6' },
{ saturation: -100 },
{ lightness: 55 },
{ visibility: 'on' }
]
},{
featureType: 'poi.park',
elementType: 'all',
stylers: [
{ hue: '#d0d0d0' },
{ saturation: -100 },
{ lightness: 16 },
{ visibility: 'on' }
]
}
];
var mapOptions = {
mapTypeControlOptions: {
mapTypeIds: [ 'Styled']
},
center: new google.maps.LatLng(37.96112215672197, 23.72348675727846),
zoom: 16,
mapTypeId: 'Styled'
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var styledMapType = new google.maps.StyledMapType(styles, { name: 'Styled' });
map.mapTypes.set('Styled', styledMapType);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' +
'callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
【问题讨论】:
-
您所有的地图实例都有相同的 ID,因此您不能只看到一张地图(样式)。对于您想要的每张地图,请提供适当的地图选项。
-
您不能添加更多画布并使用正确的 ID 多次调用它吗? var map = new google.maps.Map(document.getElementById('!!here your differenty id!!!'), mapOptions);
-
你能提供一个相同风格的地图样本吗?
-
Yeronimo 非常感谢,我解决了这个问题
标签: javascript jquery google-maps-api-3