PHP: Google Maps simulate moving marker on route according to predefined set of coordinates -


i trying develop site simulates moving bus on google maps according set of predefined coordinates. working on php, html , javascript (google maps api). database holding coordinates on localhost. question has actual simulation of bus moving towards coordinates in database.

to explain: database looks this:

 id    latt       lon  1.   53.4877   -2.27519  2.   53.4859   -2.27489 

etc. there 14 entries.

the php script connects database:

<?php $host = "localhost"; $user = "hidden"; $pass = "";  $databasename = "database"; $tablename = "locations";   $con = mysql_connect($host, $user, $pass); $dbs = mysql_select_db($databasename, $con);  $result = mysql_query("select * $tablename");  $data = array();  while ($row = mysql_fetch_row($result)) {     $data[] = $row; }    echo json_encode($data); ?> 

the javascript function:

    function movebus(map, marker)          {              $.ajax({                                                       url: 'api2.php',                                            data: "",                                          datatype: 'json',                                 async: false,                      success: function(data)                           {                      (var in data)                     {                         var row = data[i];                                      var latt = row[1];                                    var lon = row[2];                           movemarker(map, marker, latt, lon);                     }                 }              })             };  

the movemarker function:

        function movemarker( map, marker, latt, lon) {          settimeout( function(){ marker.setposition( new google.maps.latlng( latt ,       lon  ) ); }, 3500 );         }; 

as can understand have sends bus marker on last set of coordinates after loop finished instead of showing whole route makes there. have tried lots of different approaches make happen without success.

any ideas?

thank in advance.

your settimeouts finish @ same time 3500 ms. should increase time outs points based on order... position_on_route *3500.

 (var in data)                 {                     var row = data[i];                                  var latt = row[1];                                var lon = row[2];                      timeout=i*3500;                     movemarker(map, marker, latt, lon, timeout);                 }      function movemarker( map, marker, latt, lon, timeout) {      settimeout( function(){ marker.setposition( new google.maps.latlng( latt ,       lon  ) ); }, timeout );     }; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -