Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Google Maps Javascript函数放入外部文件_Javascript_File_External - Fatal编程技术网

将Google Maps Javascript函数放入外部文件

将Google Maps Javascript函数放入外部文件,javascript,file,external,Javascript,File,External,我需要将我的google maps javascript放入一个外部javascript文件中,我在这样做时遇到了一些问题。下面的代码来自我的工作HTML文件,我已经尝试将函数复制到一个外部文件中,包括脚本src标记和domstener。我遇到的问题是DomListener无法正确加载其参数。我想知道您是否可以帮助我在外部文件中输入什么,以及在HTML文件中调用什么来执行脚本 多谢各位, 安东尼 信息窗口 #地图画布{ 高度:800px; 宽度:800px; 文本对齐:居中; 左边距:51px

我需要将我的google maps javascript放入一个外部javascript文件中,我在这样做时遇到了一些问题。下面的代码来自我的工作HTML文件,我已经尝试将函数复制到一个外部文件中,包括脚本src标记和domstener。我遇到的问题是DomListener无法正确加载其参数。我想知道您是否可以帮助我在外部文件中输入什么,以及在HTML文件中调用什么来执行脚本

多谢各位, 安东尼


信息窗口
#地图画布{
高度:800px;
宽度:800px;
文本对齐:居中;
左边距:51px;
边际:0px;
填充:0px
}
.gm风格iw{
身高:100%!重要;
溢出:隐藏!重要;
}
函数初始化(){
var mylatng1=新的google.maps.LatLng(-25.363882150.044922);
var mylatng2=新的google.maps.LatLng(-25.363882152.044922);
变量映射选项={
缩放:6,
中心:myLatlng1
};
var map=new google.maps.map(document.getElementById('map-canvas'),
地图选项);
var contentString1='Mott Park'
var contentString2='Kilpa Park'
var infowindow=new google.maps.infowindow({});
var marker1=新的google.maps.Marker({
位置:myLatlng1,
地图:地图,
标题:“公园”
});
var marker2=新的google.maps.Marker({
位置:myLatlng2,
地图:地图,
标题:“水”
});
google.maps.event.addListener(标记1,'click',函数初始化(){
infowindow.close();//隐藏infowindow
infowindow.setContent(contentString1);//更新此标记的内容
打开(地图,标记1);
});
google.maps.event.addListener(marker2,'click',函数初始化(){
infowindow.close();//隐藏infowindow
infowindow.setContent(contentString2);//更新此标记的内容
打开(地图,标记2);
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

这对我来说很好用

这是我的view/HTML文件

<html>
<head>
    <link href="mystyle.css"  rel="stylesheet" type="text/css"/>
    <meta name="Park Map Brisbane" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Info windows</title>
        <style>
        #map-canvas {
        height: 800px;
        width: 800px;
        text-align: center;
        margin-left: 51px;
        margin: 0px;
        padding: 0px
        }
       .gm-style-iw{
       height: 100% !important;
       overflow: hidden !important;
       </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script src="/assets/scripts/test.js"></script>    
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
<html>

信息窗口
#地图画布{
高度:800px;
宽度:800px;
文本对齐:居中;
左边距:51px;
边际:0px;
填充:0px
}
.gm风格iw{
身高:100%!重要;
溢出:隐藏!重要;
脚本部分放在一个名为test.js的外部文件中


要访问我的javascript文件,我需要文件路径“/assets/scripts”。请输入脚本所在的文件路径。例如,如果它位于同一文件夹级别,它将仅为test.js。

非常感谢:):)我现在的dom侦听器有另一个问题,你认为你可能知道如何解决吗?我知道这是个问题恳求!谢谢:)
<html>
<head>
    <link href="mystyle.css"  rel="stylesheet" type="text/css"/>
    <meta name="Park Map Brisbane" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Info windows</title>
        <style>
        #map-canvas {
        height: 800px;
        width: 800px;
        text-align: center;
        margin-left: 51px;
        margin: 0px;
        padding: 0px
        }
       .gm-style-iw{
       height: 100% !important;
       overflow: hidden !important;
       </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script src="/assets/scripts/test.js"></script>    
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
<html>