在谷歌地图上显示带折线的标记

时间:2014-08-21 15:12:09

标签: google-maps

我正在尝试从数据库值中添加标记到折线,但是当我添加标记的代码时,折线不显示,标记也不显示。 我从数据库中获取每个人身份的坐标,并在地图上显示折线。我想添加标记或infowindows,但没有这样做。 dynamic.php

    <?php
    include "connection.php";
    $i=0;
    $table = mysql_query ("select distinct TeamWorkerId from Map");
    while ($row = mysql_fetch_array($table))
    {
        $i++;

      echo "var flightPath".$i." = new google.maps.Polyline(); var infowindow".$i." = new google.maps.InfoWindow();  function drawLine".$i."() {
        var flightPlanCoordinates".$i." = [";
        $workerid = $row["TeamWorkerId"];
       $ttable= mysql_query("select * from Map where TeamWorkerId='$workerid'");
       while ($trow = mysql_fetch_array($ttable))
       {

         echo "new google.maps.LatLng(".$trow[3]."),";
       }
        echo "];

        flightPath".$i.".setMap(null);

        flightPath".$i." = new google.maps.Polyline({
            path: flightPlanCoordinates".$i.",
            geodesic: true,
            strokeColor: '#FF0000',
            strokeOpacity: 1.0,
            strokeWeight: 2
        });

      google.maps.event.addListener(flightPath".$i.", 'click', function(event) {


            infowindow".$i.".setPosition(event.flightPlanCoordinates".$i.");
            infowindow".$i.".open(map);
        });





        flightPath".$i.".setMap(map);


    }";

Testing.php



    function initialize() 
    {
        var mapOptions = 
        {
            zoom: 3,
            center: new google.maps.LatLng(37.772323,-122.214897),
            mapTypeId: google.maps.MapTypeId.TERRAIN
        };

        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);


    }


    google.maps.event.addDomListener(window, 'load', initialize); </script>
      </head>
      <body >
      <script language="javascript">
        function view ()
        {
            alert ('called');
            drawLine1();
        }
      </script>
      <input type="button" value="show"  onclick='view();'/>
        <div id="map-canvas"></div>
      </body>
    </html>

    <script>
    $(document).ready(function(e) {

    setInterval(
    function () {
        $.get("dynamic.php",function (data) {
        //  alert (data);
            eval (data);
            });
    }
            ,60000);
    });

    </script>

1 个答案:

答案 0 :(得分:0)

var map;

地图似乎是空的。 我建议你在一个部分做所有的PHP代码,在另一个部分做js,混合两者可能很难阅读和调试