i'm newbie in php mysql and google maps v3. i have a problems in google maps v3. i made traceroute web based and map the traceroute's result in the google maps v3 for my final project of my college education. i have try so many tutorials but it didn't work. i also have tried the tutorials in this forum but nothing worked. so my problem is i cannot display multiple markers that i got the location data from database. maybe because i'm newbie and do not know how to do. i also confuse with the looping to show the markers. so here is the code
<?php
error_reporting(E_ALL ^ (E_NOTICE));
ini_set('max_execution_time', 360);
$enable_log_user = FALSE;
global $ip, $host_name, $host_ip;
$host = @$_POST['host'];
$trace = @$_POST['trace'];
$self = $_SERVER['PHP_SELF'];
include("phpsqlajax_dbinfo.php");
$connection = mysql_connect ('127.0.0.1', $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
?>
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>PHP/MySQL & Google Maps Example</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
//<![CDATA[
</script>
</head>
<body onload="initialize()">
var pinImage = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_xpin_letter_withshadow&chld=pin_star|%E2%80%A2|CC3300|000000|FF9900",
new google.maps.Size (70, 83),
new google.maps.Point (0,0),
new google.maps.Point (10,34));
var pinShadow = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size (89, 85),
new google.maps.Point (0, 0),
new google.maps.point (12, 35));
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(41.258531,-96.012599);
var myOptions = {
zoom: 2,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
<!-- var infoWindow = new google.maps.InfoWindow; -->
}
</script>
<form name="tools" action="<?php $self ?>" method="post">
<p><font size="2">Your IP is <?php $ip ?> </font></p>
<input type="text" name="host" value=""></input>
<input type="submit" name="trace" value="Traceroute!"></input>
</form>
<?php
if ($_POST['submit'])
{
if (($host == 'Enter Host or IP') || ($host == "")) {
echo '<br><br>You must enter a valid Host or IP address.';
exit; }
if(eregi("^[a-z]", $host))
{
$host_name = $host;
$host_ip = gethostbyname($host);
}
else
{
$host_name = gethostbyaddr($host);
$host_ip = $host;
}
}
$host= preg_replace ("[-a-z0-9!#$%&\'*+/=?^_`{|}~]","",$host);
$command = "tracert $host";
$fp = shell_exec("$command 2>&1");
$output .= (htmlentities(trim($fp)));
echo "<pre>$output</pre>";
echo '<br/>';
$array = array($output);
$space_separated = implode(" ", $array);
function explodeRows($data) {
$rowsArr = explode("\n", $data);
return $rowsArr;
}
function explodeTabs($singleLine) {
$parsed = preg_split('/ +/', $singleLine);
return $parsed;
}
$data = $space_separated;
$rowsArr = explodeRows($data);
for($a=3;$a<count($rowsArr)-2;$a++)
{
$lineDetails[$a] = explodeTabs($rowsArr[$a]);
if (empty($lineDetails[$a][9]))
{
$ipList[] = $lineDetails[$a][8];
}
else
{
$ipList[] = substr($lineDetails[$a][9], 1, -1);
}
}
for ($b=0; $b<count($ipList); $b++)
{
if ($ipList[$b] != "")
{
$arrLine[]=$ipList[$b];
}
}
function ip_address_to_number($IPaddress)
{
if ($IPaddress == "") {
return 0;
} else {
$ips = explode (".", "$IPaddress");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
for($c=0; $c<count($arrLine); $c++) {
$integer[] = ip_address_to_number($arrLine[$c]);
}
foreach ($integer as $lokasi) {
$query = "SELECT cl.locId, cl.country as country, cl.region as region, cl.city as city, cl.postalCode as postalCode, cl.latitude as latitude, cl.longitude as longitude, cl.metroCode as metroCode, cl.areaCode as areaCode
FROM (SELECT locId as idcihuy FROM cityblocks WHERE $lokasi BETWEEN startIpNum AND endIpNum) cb, citylocation cl WHERE cb.idcihuy = cl.locId";
$result = mysql_query($query);
while ($location = @mysql_fetch_assoc($result)){
$country[] = $location['country'];
$region[] = $location['region'];
$city[] = $location['city'];
$postalCode[] = $location['postalCode'];
$latitude[] = $location['latitude'];
$longitude[] = $location['longitude'];
$metroCode[] = $location['metroCode'];
$areaCode[] = $location['areaCode'];
}
}
?>
<script type="text/javascript">
var point = new google.maps.LatLng(<?php echo $latitude ?>, <?php echo $longitude; ?>);
var icon = pinImage;
var marker = new google.maps.Marker({
map: map,
position: point,
icon: pinImage,
shadow: pinShadow
});
</script>
<div id="map_canvas" style="width: 900px; height: 500px"></div>
</body>
</html>
okay, here is my html source code, yes there's something wrong it seems :
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>PHP/MySQL & Google Maps Example</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
//<![CDATA[
var pinImage = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_xpin_letter_withshadow&chld=pin_star|%E2%80%A2|CC3300|000000|FF9900",
new google.maps.Size (70, 83),
new google.maps.Point (0,0),
new google.maps.Point (10,34));
var pinShadow = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size (89, 85),
new google.maps.Point (0, 0),
new google.maps.point (12, 35));
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(41.258531,-96.012599);
var myOptions = {
zoom: 2,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
<!-- var infoWindow = new google.maps.InfoWindow; -->
}
</script>
</head>
<body onload="initialize()">
<form name="tools" action="" method="post">
<p><font size="2">Your IP is </font></p>
<input type="text" name="host" value=""></input>
<input type="submit" name="trace" value="Traceroute!"></input>
</form>
<pre>Tracing route to detik.com [203.190.242.69]
over a maximum of 30 hops:
1 * * * Request timed out.
2 199 ms 177 ms 179 ms 192.168.36.11
3 385 ms 359 ms 299 ms 192.168.39.8
4 2005 ms 1400 ms 1536 ms 192.168.39.8
5 1857 ms 1277 ms 1874 ms 192.168.36.11
6 2359 ms 3401 ms * 192.168.39.196
7 2477 ms 2641 ms * 114.127.254.78
8 2230 ms 1203 ms 1570 ms 114.127.254.2
9 1595 ms 1642 ms 3005 ms giga-0-0.openixp.net [218.100.27.129]
10 * * * Request timed out.
11 * 2517 ms 3294 ms 203.190.244.6
12 1632 ms 2961 ms 1297 ms 203.190.242.69
Trace complete.</pre><br/>
<script type="text/javascript">
var point = new google.maps.LatLng(-5.0000, 120.0000);
var icon = pinImage;
var marker = new google.maps.Marker({
map: map,
position: point,
icon: pinImage,
shadow: pinShadow
});
</script>
<div id="map_canvas" style="width: 900px; height: 500px"></div>
</body>
</html>
well, i'm really sorry if you guys read my code. it looks mess. because i don't know how to display the code well. the most important thing i want to be helped is in the maps. for how to show all the markers. especially the looping. the google maps doesn't show the markers. it only display the maps. so for all the masters who read this question. i just need your help as soon as possible. i'm really sorry if my english was bad and my mistake to you guys. thanks in advance.