两个风格的谷歌地图在一个页面上
Two styled Google maps on single page
如果能帮助我在一个页面上设置两个Google地图(API 3),我将非常感激。他们有一些共同的风格。我可以让一个运行,但不能让两个同时运行。
- http://theredfrog.com/new/temp3.html -一张地图(ok)
- http://theredfrog.com/new/temp4.html -两张地图(破碎)
脚本如下:
<script type="text/javascript">
function initialize() {
var styles = [
....
];
var hulloptions = {
mapTypeControlOptions: {
mapTypeIds: [ 'Styled']
},
center: new google.maps.LatLng(53.7413176, -0.3353987),
zoom: 15,
mapTypeId: 'StyledHull'
};
var leedsoptions = {
mapTypeControlOptions: {
mapTypeIds: [ 'Styled']
},
center: new google.maps.LatLng(53.796177,-1.541862),
zoom: 15,
mapTypeId: 'StyledLeeds'
};
maphull = new google.maps.Map(document.getElementById("map-hull"),hulloptions);
mapleeds = new google.maps.Map(document.getElementById("map-leeds"),leedsoptions);
var image = './skin/logo.png';
var HullLatLng = new google.maps.LatLng(53.7413176, -0.3353987);
var LeedsLatLng = new google.maps.LatLng(53.796177,-1.541862);
var rfdMarkerHull = new google.maps.Marker({
position: HullLatLng,
map: maphull,
icon: image
});
var rfdMarkerLeeds = new google.maps.Marker({
position: LeedsLatLng,
map: leedshull,
icon: image
});
var styledMapTypeHull = new google.maps.StyledMapTypeHull(styles, { name: 'RFD Hull' });
var styledMapTypeLeeds = new google.maps.StyledMapTypeLeeds(styles, { name: 'RFD Leeds' });
maphull.mapTypes.set('StyledHull', styledMapTypeHull);
mapleeds.mapTypes.set('StyledLeeds', styledMapTypeLeeds);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
这两行看起来不对:
var styledMapTypeHull = new google.maps.StyledMapTypeHull(styles, { name: 'RFD Hull' });
var styledMapTypeLeeds = new google.maps.StyledMapTypeLeeds(styles, { name: 'RFD Leeds' });
你不会在JavaScript控制台得到一个错误吗?
我想你的意思是:
var styledMapTypeHull = new google.maps.StyledMapType( styles, {
name: 'RFD Hull'
});
var styledMapTypeLeeds = new google.maps.StyledMapType( styles, {
name: 'RFD Leeds'
});
(也为较短的行重新格式化)
这里有一些更多的信息和一个工作示例。
现在,我尝试你的第二个地图与开发人员工具在Chrome中打开,我看到还有其他错误之前,它甚至得到那么远。
第一个警告:
Warning: you have included the Google Maps API multiple times
on this page. This may cause unexpected errors.
则plugins.js
中lazyload
未定义:
$(".lazy").lazyload({
effect: "fadeIn",
effectspeed: 600,
failure_limit: 10
});
然后在一些Maps API压缩代码中出现了一个神秘的错误,但是如果你看一下调用堆栈,你会在堆栈中看到initialize
函数,如果你点击它,它会转到这一行:
mapleeds = new google.maps.Map(document.getElementById("map-leeds"),leedsoptions);
将其粘贴到JavaScript控制台,你就会看到哪里出错了:
document.getElementById("map-leeds")
还有更多的错误,甚至在我看到你的代码时看到的问题之前。
所以你有一些调试要做。您熟悉Chrome或其他浏览器中的开发人员工具吗?如果没有,现在是时候了!
您的问题是(您需要使用调试器运行您的代码):
-
拼写错误(
map: mapleeds,
notmap: leedshull,
-
排序,你不能在初始化变量之前使用它们
-
这些是无效的:
google.maps.StyledMapTypeHull
,google.maps.StyledMapTypeLeeds
(也许搜索和替换出错了。应该是google.maps.StyledMapType
<script type="text/javascript"> var maphull = null; var mapleeds = null; function initialize() { var styles = [ { stylers: [ { saturation: -100 } ] },{ featureType: 'water', elementType: 'all', stylers: [ { lightness: -74 }, { visibility: 'on' } ] },{ featureType: 'landscape', elementType: 'geometry', stylers: [ { lightness: -26 }, { visibility: 'simplified' } ] },{ featureType: 'road', elementType: 'geometry', stylers: [ { hue: '#efefef' }, { lightness: 83 }, { visibility: 'simplified' } ] },{ featureType: 'poi', elementType: 'all', stylers: [ { hue: '#999999' }, { saturation: -100 }, { lightness: -23 }, { visibility: 'on' } ] },{ featureType: 'road', elementType: 'labels', stylers: [ { saturation: -100 }, { visibility: 'on' } ] } ]; var hulloptions = { mapTypeControlOptions: { mapTypeIds: [ 'Styled'] }, center: new google.maps.LatLng(53.7413176, -0.3353987), zoom: 15, mapTypeId: 'StyledHull' }; var leedsoptions = { mapTypeControlOptions: { mapTypeIds: [ 'Styled'] }, center: new google.maps.LatLng(53.796177,-1.541862), zoom: 15, mapTypeId: 'StyledLeeds' }; var image = './skin/logo.png'; var HullLatLng = new google.maps.LatLng(53.7413176, -0.3353987); var LeedsLatLng = new google.maps.LatLng(53.796177,-1.541862); var styledMapTypeHull = new google.maps.StyledMapType(styles, { name: 'RFD Hull' }); var styledMapTypeLeeds = new google.maps.StyledMapType(styles, { name: 'RFD Leeds' }); maphull = new google.maps.Map(document.getElementById("map-hull"),hulloptions); mapleeds = new google.maps.Map(document.getElementById("map-leeds"),leedsoptions); maphull.mapTypes.set('StyledHull', styledMapTypeHull); mapleeds.mapTypes.set('StyledLeeds', styledMapTypeLeeds); var rfdMarkerHull = new google.maps.Marker({ position: HullLatLng, map: maphull, icon: image }); var rfdMarkerLeeds = new google.maps.Marker({ position: LeedsLatLng, map: mapleeds, icon: image }); } google.maps.event.addDomListener(window, 'load', initialize); </script>
相关文章:
- javascript函数,它接受两个输入:一个对象和一个键,并返回对象中该键的相应值
- 在输入字段上有两个函数调用,一个在Blur上,一个不在Angular中
- 一个ajax循环有两个输出错误innerHTML
- 将两个Json提要合并为一个,并按时间排序
- 为什么jQuery文件的函数中有两个参数,但只接收一个参数
- 使用javascript将两个文本框值相加到表中的另一个文本框中
- 当两个单独的单词被放在目标上时,使用Jquery获取一个值
- 为两个ID设置一个变量的正确语法
- webgl在一个正方形上操纵两个纹理
- 一个jsp中有两个操作URL
- javascript测试是否存在两个标志中的任何一个
- Jquery:当两个或多个条件为true时,选择一个元素
- 使用一个表达式将两个变量分配给相同的值
- react-让一个元素返回两个相邻的<tr>标签
- 同一事物的两个函数,一个崩溃,另一个不崩溃,为什么
- 检查来自不同数组的两个元素的一个属性是否相等
- 保存两个模型(属于第三个模型)和一个提交
- 一个具有两个图像按钮的表单在只能按下一个按钮的情况下发送两个按钮值
- 将两个express应用程序封装在一个应用程序中
- 一个Web应用程序上有两个Java脚本