Google API에서 MySql 및 PHP의 데이터를 가져와 자동차가 움직일 때 증가하는 폴리 라인 그리기


9

MySQL과 PHP에서 데이터를 가져 와서 자동차가 애니메이션과 함께 움직일 때 (이 사이트와 같은 http://econym.org.uk/gmap/example_cartrip2.htm ) Google지도에 폴리 라인을 표시하고 싶었습니다 . 이를 위해 Google API 자습서 Polyline 의 코드를 참조했습니다 . 또한 다음과 같이 내 SQL 에서이 데이터를 가져 왔습니다.

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

            downloadUrl("xmltry.php", function(data) {
        var xml = data.responseXML;

        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            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,
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  flightPath.setMap(map);

      });

        }

        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() {}

.php 파일 :

<?php
//require("phpsqlajax_dbinfo.php");
include 'common_db.inc';
// Start XML file, create parent node

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node); 

// Opens a connection to a MySQL server

$connection=mysql_connect ("$dbserver", "$dbuser", "$dbpass");
if (!$connection) {  die('Not connected : ' . mysql_error());} 

// Set the active MySQL database

$db_selected = mysql_select_db($dbname, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
} 

// Select all the rows in the markers table

$query = "SELECT  `lat`, `lon` FROM current_location Where Device_ID='HGS1005'";
$result = mysql_query($query);
if (!$result) {  
  die('Invalid query: ' . mysql_error());
} 

header("Content-type: text/xml"); 

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){  
  // ADD TO XML DOCUMENT NODE  
  $node = $dom->createElement("marker");  
  $newnode = $parnode->appendChild($node);  
  $newnode->setAttribute("lat", $row['lat']);  
  $newnode->setAttribute("lon", $row['lon']);  
  } 

echo $dom->saveXML();

?>

그러나 이제는 첫 번째 참조 사이트에 표시된 것처럼 애니메이션으로 폴리 라인을 표시하고 싶었 습니다. 어느 하나의 참조를 제안하거나 동일하게 도와 줄 수 있습니까? 이 결과는 정확하지만 http://econym.org.uk/gmap/example_cartrip2.htm 과 같이 애니메이션을 원합니다. 여기에 이미지 설명을 입력하십시오 이번에는 제목과 설명 부분을 이해하기를 바랍니다.

답변:


2

로부터 폴리 라인 (노트에 대한지도 자바 스크립트 API 문서 path속성) :

폴리 라인의 순서대로 정렬 된 좌표. 이 경로는 LatLngs의 간단한 배열 또는 LatLngs의 MVCArray를 사용하여 지정할 수 있습니다. 간단한 배열을 전달하면 MVCArray로 변환됩니다. MVCArray 에서 LatLng를 삽입하거나 제거하면 맵의 폴리 라인이 자동으로 업데이트됩니다 .

그것을 알고, 나는 다음과 같이 시도 할 것입니다 :

// I assume you've got your GPS signal pumping updates to your client.
// Insert a new GPS point into your Polyline's point array.
function OnGpsPulse(newLat, newLon)
{
  // Insert a new point at the end of the LatLng Array.
  pointIndex = flightPlanCoordinates.length;      
  flightPlanCoordinates[pointIndex]=new google.maps.LatLng(newLat, newLon);

  // And the line should automatically update in the map.
}

나중에 생각할 때, 각 GPS 펄스는 두 곳에서 처리하고 싶을 수있는 이벤트를 전달해야합니다. 먼저 차량의 위치를 ​​무기한 저장하려면 서버 측에서 서버 측을 수집하여 데이터베이스에 푸시해야합니다. 그러나 차량이 주행하는 동안 선을 그리려면 해당 기능을 클라이언트에 유지할 수 있습니다.


답장을 보내 주셔서 감사하지만 내 데이터베이스 ieMySQL에 데이터 저장소가 있습니다. 나는이 예 (같이 트랙의 애니메이션을 보여주고 싶었다 그 내 차량이 이동 한 곳의 라이브 추적하지만 역사하지 않으 econym.org.uk/gmap/example_cartrip2.htm을 ). 저장된 데이터에 애니메이션을 추가하고 싶었습니다. 첫 번째 링크에서와 같이이 이미지가 이동하면 자동차 이미지 (예 : png)가 이동하고 차량 트랙이 그려집니다.
Pari
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.