<body>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAeNsNnRXUdrpgSw3qfvhz5hRHchrjOSPM-moa2HMmJZw-0fE6VhTsARfVd9x1Dg8TowZALqHIOcO20g" type="text/javascript"></script>
<script type="text/javascript">
var map
var lat = 13.81674404684894
var lng = 100.62034606933594
var xmlhttp
var point
var geocoder = null;
var address = null;
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
var bounds = new GLatLngBounds();
var ovcontrol = new GOverviewMapControl(new GSize(150,150));
point = new GLatLng(lat,lng,true);
map.setCenter(point, 5);
map.setUIToDefault();
bounds.extend(point);
map.addControl(ovcontrol);
setInterval("loadajax()",1000*10);
}
}
function loadajax(){
xmlhttp = new XMLHttpRequest
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="ajax_1.php";
url=url+"?sid="+Math.random();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4){
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
data_split();
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function data_split() {
var objText = document.getElementById("txtHint").value;
var e = objText.split(",");
var Marklat = parseFloat(e[1]);
var Marklng = parseFloat(e[2]);
var sta = e[0];
mark(Mlat,Mlng,sta);
}
function mark(Marklat,Marklng,sta){
var iconn = new GIcon(G_DEFAULT_ICON);
iconn.iconSize = new GSize(25,25);
if( sta == 'A'){
iconn.image = "green.png";
}else
iconn.image = "red.png";
map.clearOverlays() ;
var markpoint = new GLatLng(Marklat,Marklng,true);
geocoder = new GClientGeocoder();
marker = new GMarker(markpoint,{icon:iconn});
map.addOverlay(marker);
GEvent.addListener(marker, 'click', function(){
geocoder.getLocations(markpoint, function(addresses) {
if(addresses.Status.code != 200) {
alert("reverse geocoder failed to find an address for " + markpoint.toUrlValue());
} else {
var result = addresses.Placemark[0];
map.openInfoWindow(markpoint, result.address);
}
});
});
}
</script>
<script type="text/javascript"></script></head>
<body onload="load()" onunload="GUnload()">
<div id="map_canvas" style="width:1000px;height:600px"></div>
</body>
ajax_1.php
Code (PHP)
<?php
$con = mysql_connect('localhost', 'root', '1234');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("data", $con);
$result1 = mysql_query("SELECT id FROM RMC");
$q = mysql_num_rows($result1);
$sql="SELECT * FROM RMC WHERE id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $row['sta'].",";
echo $row['lat'].",";
echo $row['lon'].",";
};
mysql_close($con);
?>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAeNsNnRXUdrpgSw3qfvhz5hRHchrjOSPM-moa2HMmJZw-0fE6VhTsARfVd9x1Dg8TowZALqHIOcO20g" type="text/javascript"></script>
<script type="text/javascript">
var Marklat
var Marklng
var sta
var map
var xmlhttp
var speed
var Time
var Dat
var info
var picname
var geocoder = null;
var address = null;
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
var bounds = new GLatLngBounds();
var ovcontrol = new GOverviewMapControl(new GSize(150,150));
var point = new GLatLng(13.81674404684894,100.62034606933594,true);
map.setCenter(point, 6);
map.setUIToDefault();
bounds.extend(point);
map.addControl(ovcontrol);
setInterval("loadajax()",1000*10);
GEvent.addListener(map, 'click', function(overlay, point) {
if(point) {
geocoder.getLocations(point, function(addresses) {
if(addresses.Status.code != 200) {
}else{
address = addresses.Placemark[0];
var myHtml ="<font size=2>Point : "+point+"<br>Adderss : "+address.address+"</font>";
map.openInfoWindow(point, myHtml);
}
});
}
});
}
}
function loadajax(){
xmlhttp = new XMLHttpRequest
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="ajax.php";
url=url+"?sid="+Math.random();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4){
//document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
var objText = xmlhttp.responseText;
var e = objText.split(",");
Time = e[0];
speed = e[4];
Dat = e[6];
Marklat = parseFloat(e[2]);
Marklng = parseFloat(e[3]);
if(e[1]=="A"){
picname = "green.png";
sta = "Run";
}else if(e[1]=="V"){
picname = "red.png"
sta = "Stop";
}else{
picname = "off.png"
sta = "Shutdown";
}
mark();
}
}
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
//mark();
}
function mark(){
var iconn = new GIcon(G_DEFAULT_ICON);
iconn.iconSize = new GSize(25,25);
iconn.image = picname;
map.clearOverlays() ;
var markpoint = new GLatLng(Marklat,Marklng,true);
geocoder = new GClientGeocoder();
marker = new GMarker(markpoint,{icon:iconn});
map.addOverlay(marker);
GEvent.addListener(marker, 'click', function(){
geocoder.getLocations(markpoint, function(addresses) {
if(addresses.Status.code != 200) {
alert("reverse geocoder failed to find an address for " + markpoint.toUrlValue());
} else {
var result = addresses.Placemark[0];
var myml = "<font size=2.5>Date : "+Dat+ " Time : " +Time+
"<br>Status : "+sta+
"<br>Speed : "+speed+
"<br>Lat : "+Marklat+" Long : "+Marklng+
"<br>Address : "+result.address+"</font>";
map.openInfoWindow(markpoint, myml);
}
});
});
//return markpoint;
}
</script>
<script type="text/javascript"></script></head>
<body onload="loadajax(); load();" onunload="GUnload()">
<div id="map_canvas" style="width:1000px;height:600px"></div>
เป็นไฟล์ Ajax
Code (PHP)
<?php
$con = mysql_connect('localhost', 'root', '1234');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("data", $con);
$result1 = mysql_query("SELECT id FROM RMC");
$q = mysql_num_rows($result1);
$sql="SELECT * FROM RMC WHERE id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) { //speed direc Dat deg
echo $row['Tim']." ,";
echo $row['sta'].",";
echo $row['lat'].",";
echo $row['lon'].",";
echo $row['speed'].",";
echo $row['drirec'].",";
echo $row['Dat'].",";
echo $row['deg'];
};
mysql_close($con);
?>