javascript - Real Time mySQL, PHP Google Maps API Update -
i have android app sending gps coordinates in 1 sec. interval php , mysql on server. them have site location of device can tracked in real time on google maps. problem when call php script query new coordinates in mysql, runs perfect first time , gives me latest coordinates use on google maps, after first loop , keep on givimg me same value , if database has been updated.
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>horse tracker © 2013 abiapps</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link type="text/css" href="style.css" rel="stylesheet" media="all" /> <script type="text/javascript"src="http://maps.google.com/maps/api/js?********&sensor=false"></script> <script type="text/javascript" src="map.js"></script> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> </head> <body> <h1>horse tracker © 2013 abiapps </h1> <input type="button" value="getvalues" id="getvalues" /> <input type="button" value="changevalues" id="changevalues" /> <div id="map"></div> <script> (function() { window.onload = function() { var mapdiv = document.getelementbyid('map'); var latlng = new google.maps.latlng(35.694094,23.683620); var options = { center: latlng, zoom: 4, maptypeid: google.maps.maptypeid.roadmap, maptypecontrol: true, navigationcontrol: true, navigationcontroloptions: { position: google.maps.controlposition.top_right }, maptypecontroloptions: { style: google.maps.maptypecontrolstyle.dropdown_menu }, streetviewcontrol: false, backgroundcolor: '#0000ff' }; var map = new google.maps.map(mapdiv, options); document.getelementbyid('getvalues').onclick = function() { alert('current zoom level ' + map.getzoom()); alert('current center ' + map.getcenter()); } document.getelementbyid('changevalues').onclick = function() { var latlng = new google.maps.latlng(<?php include 'getgps.inc.php';?>); map.setcenter(latlng); } var = 1; function autoupdate() { = a; var latlng = new google.maps.latlng(<?php include 'getgps.inc.php';?>); map.setcenter(latlng); alert('<?php include 'getgps.inc.php';?>'); settimeout(autoupdate, 1000); } autoupdate(); } })(); </script> </body> </html>
and php code..
<?php $host="localhost"; $username="*****"; $password="*****"; $db_name="horsetrack"; $tbl_name="gps"; // $body = ""; // connect server , select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select db"); $sql="select * $tbl_name order id desc limit 1 "; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ $id = $rows['id']; $datetime = $rows["datetime"]; $rname = $rows["rider"]; $rlat = $rows["lat"]; $rlng = $rows["lng"]; $body = $rlat.','.$rlng; } echo $body; mysql_close(); //close database ?>
im getting same result in alert(); firt query if add row database
you realize php code executed on server, not client? when line executed:
alert('<?php include 'getgps.inc.php';?>');
you'll end like
alert('foo');
embedded javascript send on client. when autoupdate()
function executed in client, php code long since gone , never re-executed client, 'foo'
text never changes.
you need use ajax call fetch fresh copy of file's output each time, not re-alert embedded in page when generated.
Comments
Post a Comment