|
|
|
อยากถามผู้รู้ช่วย ดู code ของ google map api ให้ทีครับ |
|
|
|
|
|
|
|
ไฟล์หน้าแรก อ่าครับ
var map;
var geocoder;
function load() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(18.710824, 098.974740), 9);
}
GDownloadUrl("phpsqlajax_genxml.php", function (data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
var sidebar = document.getElementById('sidebar');
sidebar.innerHTML = '';
if (markers.length == 0) {
sidebar.innerHTML = 'No results found.';
return;
}
var bounds = new GLatLngBounds();
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var time = markers[i].getAttribute("time");
var marker = createMarker(point, name, address, time);
map.addOverlay(marker);
var sidebarEntry = createSidebarEntry(marker, name, address);
sidebar2.appendChild(sidebarEntry);
bounds.extend(point);
}
});
}
function createMarker(point, name, address, time) {
var marker = new GMarker(point, number);
var html = "<table width=300><tr><td>"+"<b>ชื่อสถานที่ : " + name + "</b> <br/>ที่อยู่ : " + address+"</td></tr></table>";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
function createSidebarEntry(marker, name, address) {
var div = document.createElement('div');
var html = "<b>ชื่อ : " + name + "</b> <br/>ที่อยู่ : " + address +"<br/> -*********************;
div.innerHTML = html;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
GEvent.addDomListener(div, 'click', function() {
GEvent.trigger(marker, 'click');
});
GEvent.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
GEvent.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<br/>
<br/>
<div style="width:600px; font-family:Arial,
sans-serif; font-size:11px; border:1px solid black">
<table>
<tbody>
<tr>
<td width="200" valign="top"> <div id="sidebar" style="overflow: auto; height: 362px; font-size: 11px; color: #000"></div> </td>
</td>
<td> <div id="map" style="overflow: hidden; width:400px; height:400px"></div> </td>
</tr>
</tbody>
</table>
</div>
</body>
ไฟล์ .. phpsqlajax_genxml
<?php
require("connect.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
$connection=mysql_connect ($hostname, $username, $password);
mysql_query("SET NAMES UTF-8",$connection);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
echo '<markers>';
while ($row = @mysql_fetch_assoc($result)){
echo '<markers ';
echo 'id="' . parseToXML($row['id']) . '" ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'Time="' . $row['time'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
ตอนที่คิวรี่แล้วมันไม่ออกที่ sidebar อ่าครับ
Tag : PHP
|
ประวัติการแก้ไข 2012-01-21 19:34:17 2012-01-21 19:54:20 2012-01-21 19:54:22
|
|
|
|
|
Date :
2012-01-21 19:14:37 |
By :
KaJooNoi |
View :
1291 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ที่มันออกมาอ่าครับ
|
|
|
|
|
Date :
2012-01-21 19:19:52 |
By :
KaJooNoi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมไม่รู้ว่มันจะเป็นที่ เวอร์ชั่นของ mql ด้วยเปล่าอ่าคับ ?
|
|
|
|
|
Date :
2012-01-22 00:05:47 |
By :
KaJooNoi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้รียังครับ ผมก็ติดอยู่ตรงนี้เหมือนกันครับ
|
|
|
|
|
Date :
2012-01-28 19:44:01 |
By :
raptor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อันนี้ Index.php
Code (PHP)
<!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>ระบบค้นหาร้านอาหาร</title>
<script src= "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAKaJQ6galA0QmFhNdQzYuwRQnaT__a1y-hZdnJBN4Ggj_4W3wVRTkKlGxp0EJvRTbiAqcn-FCYSTDog" type="text/javascript" ></script>
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
//<![CDATA[
var circle = null;
var circle2 = null;
var map;
var geocoder;
var iconBlue = new GIcon();
iconBlue.image = 'restaurant2.png';
iconBlue.shadow = 'restaurant2.png';
iconBlue.iconSize = new GSize(20, 22);
iconBlue.shadowSize = new GSize(1, 1);
iconBlue.iconAnchor = new GPoint(12, 8);
iconBlue.infoWindowAnchor = new GPoint(5, 1);
var icongreen = new GIcon();
icongreen.image = 'restaurant2.png';
icongreen.shadow = 'restaurant2.png';
icongreen.iconSize = new GSize(25, 27);
icongreen.shadowSize = new GSize(1, 1);
icongreen.iconAnchor = new GPoint(12, 8);
icongreen.infoWindowAnchor = new GPoint(5, 1);
var iconx = new GIcon();
iconx.image = 'restaurant2.png';
iconx.shadow = 'restaurant2.png';
iconx.iconSize = new GSize(20, 20);
iconx.shadowSize = new GSize(1, 1);
iconx.iconAnchor = new GPoint(12, 8);
iconx.infoWindowAnchor = new GPoint(5, 1);
var customIcons = [];
customIcons["ปิด"] = iconBlue;
customIcons["เปิด"] = icongreen;
customIcons["cross"] = iconx;
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
geocoder = new GClientGeocoder();
map.addMapType(G_PHYSICAL_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(14.355158,100.563869), 13);
GDownloadUrl("phpsqlajax_markers.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
var sidebar2 = document.getElementById('sidebar2');
sidebar2.innerHTML = '';
if (markers.length == 0) {
sidebar2.innerHTML = 'No results found.';
return;
}
var bounds = new GLatLngBounds();
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var images = markers[i].getAttribute("images");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(point, name, address, type, images);
map.addOverlay(marker);
var sidebarEntry = createSidebarEntry(marker, name, address, type, images);
sidebar2.appendChild(sidebarEntry);
bounds.extend(point);
}
});
}
}
function createMarker(point, name, address, type, images) {
var marker = new GMarker(point, customIcons[type]);
var html = "<table width=300><tr><td><img style= ' width:70px; height:50px;' src ='images/" + images + "'></td><td>"+"<b>ชื่อสถานที่ : " + name + "</b> <br/>ที่อยู่ : " + address+"</td></tr></table>";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
function createSidebarEntry(marker, name, address, type, images) {
var div = document.createElement('div');
var html = "<b>ชื่อ : " + name + "</b> <br/>ที่อยู่ : " + address +"<br/> -----------------------------------------------";
div.innerHTML = html;
div.style.cursor = 'pointer';
div.style.marginBottom = '1px';
GEvent.addDomListener(div, 'click', function() {
GEvent.trigger(marker, 'click');
});
GEvent.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
GEvent.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="main">
<div class="head">
<div class="logo">
<img src="images/header.png">
</div>
</div>
<div id="content_wrap">
<div class="content_left">
<div id="map_canvas" style="width: 800px; height: 500px"></div>
</div>
<div class="menu_right">
<div id="firstpane" class="menu_list"> <!--Code for menu starts here-->
<a href="#"><p class="menu_head">หน้าแรก</p></a>
<a href="#"><p class="menu_head">ค้นหาร้านอาหาร</p></a>
<a href="#"><p class="menu_head">แนะนำร้านอาหาร</p></a>
<a href="#"><p class="menu_head">ขอเส้นทาง</p></a>
<a href="#"><p class="menu_head">ติดต่อสอบถาม</p></a>
</div>
</div>
<div class="content_right">
<div id="sidebar2" style="overflow: auto; height: 362px; font-size: 11px; color: #000"></div>
</div>
</div>
</div>
<div class="footer"></div>
</body>
</html>
อันนี้ phpsqlajax_markers.php
Code (PHP)
<?php
require("config.inc.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
$connection=mysql_connect ($hostname, $username, $password);
mysql_query("SET NAMES UTF8",$connection);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . $row['address'] . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo 'images="' . $row['images'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
config.inc.php
Code (PHP)
<?php
$hostname = "localhost";
$username = "root";
$password = "8992";
$database = "mapapi";
$connect = mysql_connect( $hostname,$username,$password) or die ("ติดต่อ Mysql ไม่ได้ ");
mysql_select_db($database) or die("ติดต่อ database ไม่ได้");
@session_start();
?>
ลองดูครับ
|
|
|
|
|
Date :
2012-02-16 18:56:45 |
By :
aobbie_p |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|