如何使用php,javascript在谷歌地图中显示两个移动物体

时间:2015-05-07 12:39:20

标签: javascript php google-maps polyline

我正在尝试使用php,javascript在谷歌地图上显示多个移动物体的轨迹(使用不同的颜色)。我成功地显示了单个对象。但对于多重,我不知道。如果有人有想法,请帮助我。这是我的单个对象的代码。

function load(a) {

            var point;
            var flightPlanCoordinates = new Array();
            var map = new google.maps.Map(document.getElementById("map"), {
                center: new google.maps.LatLng(21.161, 72.838),
                zoom: 6,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControl: false,
                mapTypeControlOptions: {
                    style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
                },
                navigationControl: true,
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.SMALL
                }
            });

            setInterval(function () {
            downloadUrl("dynamic.php?imei=" + a, function (data) {
                var xml = data.responseXML;

                var markers = xml.documentElement.getElementsByTagName("marker");
                for (var i = 0; i < markers.length; i++) {
                    parseFloat(markers[i].getAttribute("imei")));
                    point = new google.maps.LatLng(
                            parseFloat(markers[i].getAttribute("lat")),
                            parseFloat(markers[i].getAttribute("lon")));
                    flightPlanCoordinates[i] = point;
                }
                var flightPath = new google.maps.Polyline({
                    path: flightPlanCoordinates,
                    geodesic: true,
                    strokeColor: "black",
                    strokeOpacity: 1.0,
                    strokeWeight: 2
                });

                flightPath.setMap(map);

            })
            }, 3000);

        }
        function downloadUrl(url, callback) {
            var request = window.ActiveXObject ?
                    new ActiveXObject('Microsoft.XMLHTTP') :
                    new XMLHttpRequest;

            request.onreadystatechange = function () {
                if (request.readyState == 4) {
                    request.onreadystatechange = doNothing;
                    callback(request, request.status);
                }
            };

            request.open('GET', url, true);
            request.send(null);
        }


        function doNothing() {
        }

0 个答案:

没有答案