Hi, thanks for reply.
I did as you said, but the map is drawn empty. Maybe The google script doesn't support string code that "var coordinates" has.
------------- Here is the php code: ------------- (getuser.php)
PHP Code:
<?php
$q=$_GET["q"];
$s=$_GET["s"];
$l=$_GET["l"];
$con = mysql_connect('localhost', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("awc", $con);
$sql="SELECT * FROM locations WHERE mod(Id,".$q." ) = 0 AND str_to_date('".$s."','%Y-%m-%d %T') > ReceiveTime limit " .$l. "";
// str_to_date('".$s."','%Y-%m-%d %k:%i:%s')
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "new Glatlng(" . $row['Latitude'] . "," . $row['Longitude'] . "),";
}
mysql_close($con);
?>
--------------- And-here is the javascript: -------------- (selectuser.js)
Code:
var xmlHttp
function showUser(steppi, start, limitti)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url= url + "?q=" + steppi + "&s=" + start + "&l=" + limitti
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var coordinates = xmlHttp.responseText;
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(60.1766666666667,25.776666666666), 6);
var polyline = new GPolyline([
new GLatLng(60.1592,24.9227),
+ coordinates +
new GLatLng(60.1592,12.9257),
], "#ff0000", 3, 0.9);
map.addOverlay(polyline);
}
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
---------------- And lastly index.html --------------------
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="selectuser.js"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA8932eZOB5JEYtvZPasq4FxQ54HRG6gq8VpzycMbCIkcuTGCE9hRMM
9j97YB3eghRasY7q3LcbbWseg"
type="text/javascript"></script>
</head>
<body>
<h2>Arandan matka Combine4/2007</h2>
Alkoi: 2007-12-10 12:30:00 ja päättyi: 2007-12-14 07:35:00
<h3>Hae tiedot:</h3>
Anna aloitusaika, askelväli (yksi askel on noin 10s) ja esitettävien rivien määrä.
<form>
steppi: <input id="steppi" name="steppi" value="60" type="text"> Alkuaika: <input id="startti" name="startti" type="text" value="2009-12-10 12:30:00"> limit: <input id="limitti" name="limitti" value="10" type="text">
<input type="button" value="Hae" onclick="showUser(steppi.value, startti.value, limitti.value);load()" >
<div id="map" style="width: 500px; height: 400px"></div>
</body>
</html>
Bookmarks