简体   繁体   中英

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.

Below is the script, and I have a file server side with GPS co-ordinates called "gps.txt". 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.

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>标记。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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