简体   繁体   English

PHP / JavaScript无法读取文本文件

[英]PHP/JavaScript not reading text file

I have a problem with a PHP/JavaScript I have downloaded in an example for a hardware project off the internet. 我在Internet上的硬件项目示例中下载了PHP / JavaScript,但遇到了问题。

Below is the script, and I have a file server side with GPS co-ordinates called "gps.txt". 下面是脚本,并且我在文件服务器端具有称为“ gps.txt”的GPS坐标。 By placing the 'old' "i'm here" text commands I was able to figure out that the script does not appear to be opening the "gps.txt" files hence that is why Google maps is not being updated with markers. 通过放置“旧”“我在这里”文本命令,我能够弄清楚该脚本似乎并未打开“ gps.txt”文件,因此这就是为什么未使用标记来更新Google地图的原因。

Really appreciate any suggestions you guys have. 非常感谢你们的任何建议。

<!-- Load Jquery -->

<script language="JavaScript" type="text/javascript" src="jquery-1.10.1.min.js"></script>

<!-- Load Google Maps Api -->

<!-- IMPORTANT: change the API v3 key -->

<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCU0-w2UAK0Y1rFwVsaQxkMS0upbw-Cqyk&sensor=false"></script>

<!-- Initialize Map and markers -->

<script type="text/javascript">
    var myCenter=new google.maps.LatLng(26.707687,-80.054420);
    var marker;
    var map;
    var mapProp;

    function initialize()
    {
        mapProp = {
          center:myCenter,
          zoom:15,
          mapTypeId:google.maps.MapTypeId.ROADMAP
          };
        setInterval('mark()',5000);
    }

    function mark()
    {
        map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
        var file = "gps.txt";
        $.get(file, function(txt) { 
            var lines = txt.split("\n");
            for (var i=0;i<lines.length;i++){
                console.log(lines[i]);
                var words=lines[i].split(",");
                if ((words[0]!="")&&(words[1]!=""))
                {
                    marker=new google.maps.Marker({
                          position:new google.maps.LatLng(words[0],words[1]),
                          });
                    marker.setMap(map);
                    map.setCenter(new google.maps.LatLng(words[0],words[1]));s
                }
            }
            marker.setAnimation(google.maps.Animation.BOUNCE);
        });

    }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>

<!-- Draw information table and Google Maps div -->

    <div>
        <center><br />
            <b> SIM908 GPS position DEMO </b><br /><br />
            <div id="superior" style="width:800px;border:1px solid">
                <table style="width:100%">
                    <tr>
                        <td>Time</td>
                        <td>Satellites</td>
                        <td>Speed OTG</td>
                        <td>Course</td>
                    </tr>
                    <tr>
                        <td id="time">2015 Apr 24 - 15:04</td>
                        <td id="sat"></td>
                        <td id="speed"></td>
                        <td id="course"></td>
                    </tr>
            </table>
            </div>
            <br /><br />
            <div id="googleMap" style="width:800px;height:700px;"></div>
        </center>
    </div></body>

通过评论讨论之后,我们发现该问题的答案是修复jQuery <script ...></script>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM