是否已初始化地图和标记?

时间:2013-11-28 06:06:07

标签: javascript jquery google-maps

<!DOCTYPE html>
<html>

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

<script         src="http://maps.googleapis.com/maps/api/jskey=aizaSyC04cjSCu3HVoez_JV2S4ePQGNNFwfj_9U&sensor=true">    </script>

    var myCenter=new google.maps.LatLng(41.669578,-0.907495);  
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";      //read file
        $.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]));
                document.getElementById('sat').innerHTML=words[3];
                document.getElementById('speed').innerHTML=words[4];
                document.getElementById('course').innerHTML=words[5];
                }
            }
            marker.setAnimation(google.maps.Animation.BOUNCE);
        });

    }

    google.maps.event.addDomListener(window, 'load', initialize);

    ///***this one is the load method of j-query. why should i need this.***    
    $(document).ready(function(){ 
    $("button").click(function(){
    $("#div1").load("gps.txt");
    });
  });

 </script>
 </head>

 <body>

<?php




    echo '

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


    <div id="div1">
        <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">'. date("Y M d - H:m") .'</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>
     <body>
     <button>Get External Content</button>
      /// button to access another file

   </body>
   </html>

   <?php } ?>

我试图在localhost上运行此文件,但似乎标记未显示在地图上。并且我创建的表中没有插入名为gps.txt的文件中的数据。我不知道为什么。但是,我的老师告诉我的一些建议是“加载J查询”,并初始化地图和标记。我不太确定这个版本是否已经初始化。

0 个答案:

没有答案