stereotyyppi
01-15-2008, 08:05 AM
Hi, I'm using ajax with php for getting information from mysql database. My problem is how to put the code (latitudes, longitudes) into google javascript file (not into div in the body section) and also how to load the map to see changes.
The purpose of this script is to show ships route on google map on defined date (javascript).
So it should put "new GLatLng(lat,long)," - values into javascript file.
------------------- index.html: -------------------------
<!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>
<script type="text/javascript">
function load() {
//<![CDATA[
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([
********************** Here is where the code should be put **********************
new GLatLng(60.1592,24.9227),
new GLatLng(60.1592,12.4257),
], "#ff0000", 3, 0.9);
map.addOverlay(polyline);
}
//]]>
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<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="2007-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)" ></form>
<div id="txtHint"></div>
<div id="map" style="width: 500px; height: 400px"></div>
</body>
</html>
---------------------- selectuser.js: ----------------------------
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")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
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;
}
--------------------------- getuser.php ----------------------------------
<?php
$q=$_GET["q"];
$s=$_GET["s"];
$l=$_GET["l"];
$con = mysql_connect('localhost', 'user', '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);
echo "<table border='1'>
<tr>
<th>Id</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Datumcode</th>
<th>ReceiveTime</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Id'] . "</td>";
echo "<td>" . $row['Latitude'] . "</td>";
echo "<td>" . $row['Longitude'] . "</td>";
echo "<td>" . $row['DatumCode'] . "</td>";
echo "<td>" . $row['ReceiveTime'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
The purpose of this script is to show ships route on google map on defined date (javascript).
So it should put "new GLatLng(lat,long)," - values into javascript file.
------------------- index.html: -------------------------
<!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>
<script type="text/javascript">
function load() {
//<![CDATA[
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([
********************** Here is where the code should be put **********************
new GLatLng(60.1592,24.9227),
new GLatLng(60.1592,12.4257),
], "#ff0000", 3, 0.9);
map.addOverlay(polyline);
}
//]]>
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<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="2007-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)" ></form>
<div id="txtHint"></div>
<div id="map" style="width: 500px; height: 400px"></div>
</body>
</html>
---------------------- selectuser.js: ----------------------------
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")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
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;
}
--------------------------- getuser.php ----------------------------------
<?php
$q=$_GET["q"];
$s=$_GET["s"];
$l=$_GET["l"];
$con = mysql_connect('localhost', 'user', '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);
echo "<table border='1'>
<tr>
<th>Id</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Datumcode</th>
<th>ReceiveTime</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Id'] . "</td>";
echo "<td>" . $row['Latitude'] . "</td>";
echo "<td>" . $row['Longitude'] . "</td>";
echo "<td>" . $row['DatumCode'] . "</td>";
echo "<td>" . $row['ReceiveTime'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>