I'm facing a problem to display the random locations around the location are fetching from mysql, the method found Here. and its working prefect when i give value for lat and lng directly ,but in my code after using mysql data not able to display the random location on map ,google map displaying only the location from mysql as shown in the picture. so i wish someone can help me about my problem.
the result after run the code
the database and data define as:
CREATE TABLE IF NOT EXISTS `map` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`desc` text NOT NULL,
`lat` text NOT NULL,
`lon` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `map`
--
INSERT INTO `poi_example` (`id`, `name`, `desc`, `lat`, `lon`) VALUES
(1, '100 Club', 'Oxford Street, London W1<br/>3 Nov 2010 : Buster Shuffle<br/>', '51.514980', '-0.144328'),
(2, '93 Feet East', '150 Brick Lane, London E1 6RU<br/>7 Dec 2010 : Jenny & Johnny<br/>', '51.521710', '-0.071737'),
(3, 'Adelphi Theatre', 'The Strand, London WC2E 7NA<br/>11 Oct 2010 : Love Never Dies', '51.511010', '-0.120140'),
(4, 'Albany, The', '240 Gt. Portland Street, London W1W 5QU', '51.521620', '-0.143394'),
(5, 'Aldwych Theatre', 'Aldwych, London WC2B 4DF<br/>11 Oct 2010 : Dirty Dancing', '51.513170', '-0.117503'),
(6, 'Alexandra Palace', 'Wood Green, London N22<br/>30 Oct 2010 : Lynx All-Nighter', '51.596490', '-0.109514');
and the php file for displaying the map:
<?php
$conn = mysql_connect("localhost", "hani", "hani") or die(mysql_error());
mysql_select_db("map4") or die(mysql_error());
?>
<?php
$conn = mysql_connect("localhost", "hani", "hani") or die(mysql_error());
mysql_select_db("map4") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps</title>
<style type="text/css">
body { font: normal 10pt Helvetica, Arial; }
#map { width: 1300px; height: 600px; border: 0px; padding: 0px; }
</style>
<script src="http://maps.google.com/maps/api/js?key=key=loadMap&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
//Sample code written by August Li
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
new google.maps.Size(320, 320), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
// random location method start from there
// random location method end there
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
<?php
$query = mysql_query("SELECT * FROM map")or die(mysql_error());
while($row = mysql_fetch_array($query))
{
$name = $row['name'];
$lat = $row['lat'];
$lon = $row['lon'];
$desc = $row['desc'];
echo("addMarker($lat, $lon, '<b>$name</b><br />$desc');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
</head>
<body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
<div id="map"></div>
</body>
</html>
Your code has several syntax problems :
Your function addMarker finishes before the part that generates random markers : you have to move the } after the calls to googlemaps function just before the initMap() function
google.maps.Marker1 : remove the trailing 1
, x0 = long : lng, not long
Related
i am using PHP & MYSQL on wordpress in order to retrieve data from the database that contains coordinates and display markers on the Google Map.
Markers are shown on the map with the info window contains the coordinates.
i want to retrieve more info from the database and includes it in the info window
in the debug mode it show the info that is i want to add to the info window when i uncomment it markers will not show.
code:
<?php
/*
Template Name: MAP2
*/
get_header();
?>
<!DOCTYPE html>
<html>
<head>
<title>Custom Markers</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=********&callback=initMap">
</script>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 600px;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map,currentPopup;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: new google.maps.LatLng(33.888630, 35.495480),
mapTypeId: 'roadmap'
});
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var icons = {
parking: {
icon: iconBase + 'parking_lot_maps.png'
},
library: {
icon: iconBase + 'library_maps.png'
},
info: {
icon: iconBase + 'info-i_maps.png'
}
};
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
// i need to add here the info
//icon: icons[feature.type].icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: feature.position.toString(),
//or here the info
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
var features = [
<?php
global $wpdb;
$prependStr ="";
foreach( $wpdb->get_results("SELECT siteID, latitude, longitude FROM site_coordinates2", OBJECT) as $key => $row) {
$latitude = $row->latitude;
$longitude = $row->longitude;
$info = $row->siteID;
echo $prependStr;
?>
{
position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
// info:<?php echo $info;?>,
}
<?php
$prependStr =",";
}
?>
];
for (var i = 0, feature; feature = features[i]; i++) {
addMarker(feature);
}
}
</script>
</body>
</html>
<?php
get_footer();
?>
where the AM001 is the first Site ID in the MYSQL databases
assuming that you want us sietID as info
var features = [
<?php
global $wpdb;
$prependStr ="";
foreach( $wpdb->get_results("SELECT siteID, latitude, longitude FROM site_coordinates2", OBJECT) as $key => $row) {
$latitude = $row->latitude;
$longitude = $row->longitude;
$info = $row->siteID;
echo $prependStr;
?>
{
position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
info:<?php echo $info;?>,
}
<?php
$prependStr =",";
}
?>
];
then in your var popup you should add the info text
var popup = new google.maps.InfoWindow({
content: feature.position.toString() + ' my info siteID: ' + feature.info ,
//or here the info
maxWidth: 300
});
Im trying to insert into database but it giving me an error (check the manual that corresponds to your mysql server version for the right syntax to use near (Long,Lat,name,ReturnAddress, Division)
im using php,mysql. I need to success result,
//Insert new row with user data
$query = sprintf("INSERT INTO map " .
" ( Id, Lat, Long, Name, ReturnAddress, Division ) " .
" VALUES ('%s','%s', '%s', '%s', '%s','%s');",
mysql_real_escape_string($ID),
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($name),
mysql_real_escape_string($address),
mysql_real_escape_string($type));
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
mysql_close();
and the code :
<!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>Google Maps JavaScript API v3 Example: Map Simple</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var marker;
var infowindow;
function initialize() {
var latlng = new google.maps.LatLng(37.4419, 36.1419);
var options = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var html = "<table>" +
"<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
"<tr><td>Address:</td> <td><input type='text' id='address'/></td> </tr>" +
"<tr><td>Type:</td> <td><select id='type'>" +
"<option value='normal home' SELECTED>normal home</option>" +
"<option value='villa'>villa</option>" +
"</select> </td></tr>" +
"<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
infowindow = new google.maps.InfoWindow({
content: html
});
google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
});
}
function saveData() {
var name = escape(document.getElementById("name").value);
var address = escape(document.getElementById("address").value);
var type = document.getElementById("type").value;
var latlng = marker.getPosition();
var url = "phpsqlinfo_addrow.php?name=" + name + "&address=" + address +
"&type=" + type + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
downloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length <= 1) {
infowindow.close();
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
alert(request.responseText);
callback(request.responseText, request.status);
window.open('index.php','_self',false);
}
};
request.open('GET', url, true);
request.send();
}
function doNothing() {}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map-canvas" style="width: 500px; height: 300px"></div>
<div id="message"></div>
</body>
</html>
and the database :
CREATE TABLE IF NOT EXISTS `map` (
`Id` int(20) NOT NULL AUTO_INCREMENT,
`Lat` float NOT NULL,
`Long` float NOT NULL,
`Name` varchar(100) NOT NULL,
`ReturnAddress` varchar(100) NOT NULL,
`Division` varchar(100) NOT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
long is a reserved word enclose it in backticks
`long`
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
i am using google map to create a dynamic google map that take locations(lat, lon) stored in the database using php mysql and display the selected locations by markers on the map
but the problem is that i get the map displayed with a blue color without anything else
if anyone can help me i will appreciate that
map.php
<?php
$conn = mysql_connect("localhost", "****", "*****") or die(mysql_error());
mysql_select_db("map") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps</title>
<style type="text/css">
body { font: normal 10pt Helvetica, Arial; }
#map { width: 350px; height: 300px; border: 0px; padding: 0px; }
</style>
<script src="http://maps.google.com/maps/api/js?key=mykey&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
//Sample code written by August Li
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
<?php
$query = mysql_query("SELECT * FROM poi_example")or die(mysql_error());
while($row = mysql_fetch_array($query))
{
$name = $row['name'];
$lat = $row['lat'];
$lon = $row['lon'];
$desc = $row['desc'];
echo("addmarker($lat, $lon, '<b>$name</b><br />$desc');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
</head>
<body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
<div id="map"></div>
</body>
</html>
the database is
CREATE TABLE IF NOT EXISTS `poi_example` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`desc` text NOT NULL,
`lat` text NOT NULL,
`lon` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `poi_example`
--
INSERT INTO `poi_example` (`id`, `name`, `desc`, `lat`, `lon`) VALUES
(1, '100 Club', 'Oxford Street, London W1<br/>3 Nov 2010 : Buster Shuffle<br/>', '51.514980', '-0.144328'),
(2, '93 Feet East', '150 Brick Lane, London E1 6RU<br/>7 Dec 2010 : Jenny & Johnny<br/>', '51.521710', '-0.071737'),
(3, 'Adelphi Theatre', 'The Strand, London WC2E 7NA<br/>11 Oct 2010 : Love Never Dies', '51.511010', '-0.120140'),
(4, 'Albany, The', '240 Gt. Portland Street, London W1W 5QU', '51.521620', '-0.143394'),
(5, 'Aldwych Theatre', 'Aldwych, London WC2B 4DF<br/>11 Oct 2010 : Dirty Dancing', '51.513170', '-0.117503'),
(6, 'Alexandra Palace', 'Wood Green, London N22<br/>30 Oct 2010 : Lynx All-Nighter', '51.596490', '-0.109514');
This is how it should be (sorry for the indentation):
<?php
$conn = mysql_connect("localhost:4040", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps</title>
<style type="text/css">
body { font: normal 10pt Helvetica, Arial; }
#map { width: 350px; height: 300px; border: 0px; padding: 0px; }
</style>
<script src="http://maps.google.com/maps/api/js?key=xxxxxxxxxxxxxxx&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
//Sample code written by August Li
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
<?php
$query = mysql_query("SELECT * FROM poi_example")or die(mysql_error());
while($row = mysql_fetch_array($query))
{
$name = $row['name'];
$lat = $row['lat'];
$lon = $row['lon'];
$desc = $row['desc'];
echo("addMarker($lat, $lon, '<b>$name</b><br />$desc');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
</head>
<body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
<div id="map"></div>
</body>
</html>
The issue is: addmarker in the call va addMarker in function definition (JS is case-sensitive)
I'm stuck on a current issue when I'm trying to use the custom infobox with google API v3 PHP / SQL Database. I'm having the hardest time figuring out where I messed up, the div shows up blank instead of having a map. Any help would awesome!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
var customIcons = {
Clinic: {
icon: 'icon_2.png',
},
Secondary: {
icon: 'icon_1.png',
}
};
function initialize() {
var map = new google.maps.Map(document.getElementById("map_canvas"), {
center: new google.maps.LatLng(47.6145, -122.3418),
zoom: 13,
scrollwheel: false,
mapTypeId: 'roadmap'
});
downloadUrl("xml.php", function(data) {
function createMarker(markerXML) {
var name = markerXML.getAttribute("name"),
postid = markers [i].getAttribute("post_id"),
address = markers[i].getAttribute("address"),
phone = markers[i].getAttribute("phone"),
listtype = markers[i].getAttribute("type"),
monday = markers[i].getAttribute("monday"),
tuesday = markers[i].getAttribute("tuesday"),
wednesday = markers[i].getAttribute("wednesday"),
thursday = markers[i].getAttribute("thursday"),
friday = markers[i].getAttribute("friday"),
saturday = markers[i].getAttribute("saturday"),
sunday = markers[i].getAttribute("sunday"),
type = markers[i].getAttribute("type"),
point = new google.maps.LatLng(
lat = parseFloat(markerXML.getAttribute("lat")),
lng = parseFloat(markerXML.getAttribute("lng")),
icon = customIcons[type] || {},
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(lat, lng),
icon: icon.icon,
}),
boxText = document.createElement("div");
boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
boxText.innerHTML = "<b>" + name + "</b> <br/> <i>" + listtype + "</i> <br/>" + address + "<br/>" + phone + "<br/>" + monday + tuesday + wednesday + thursday + friday + saturday + sunday;
var myOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-140, 0),
zIndex: null,
boxStyle: {
background: "url('tipbox.gif') no-repeat",
opacity: 0.75,
width: "280px"
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
var infoBox = new InfoBox(myOptions);
google.maps.event.addListener(marker, 'click', function () {
infoBox.open(map, marker);
}
});
}
var xml = data.responseXML,
markers = xml.documentElement.getElementsByTagName("marker"),
numMarkers = markers.length;
for (var i = 0; i < numMarkers; i++) {
createMarker(markers[i]);
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
<div id="map_canvas" style="width: 500px; height: 300px"></div>
Look at the javascript console and fix the errors you find there. Just commenting out dowloadUrl call should get you your map back.
You didn't provide a sample of your xml, but the second step (after fixing your javascript errors) would be to open the xml feed in your browser and see if it is valid (or you could run it through an xml validator)
This article (which it looks like you might have started with) also provides some debugging suggestions.
working version
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.