Download presentation
Presentation is loading. Please wait.
1
第四組 停車場搜尋系統 第四組 溫允中 陳欣暉 蕭積遠 李雅俐
2
建立mysql 資料表[完成] Google maps 連接 mysql[除錯中] Google map api版本問題
3
mysql web介面
4
設定資料欄位類型
5
建立一個名為wholocations的資料表
CREATE TABLE wholocations ( id int(11) NOT NULL auto_increment, lat decimal(10,6) NOT NULL default ' ', lon decimal(10,6) NOT NULL default ' ', description varchar(255) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM;
6
輸入你的api key <html> <head> <title>Who locations in London</title> <script src=" Google Maps key]" type="text/javascript"></script> </head> <body> <p><strong>Who-locations in London</strong></p> <div id="map" style="width: 800px; height: 600px"></div>
7
讀取資料庫的資料和多個圖釘點的建立 <script type="text/javascript"> //<![CDATA[ var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); map.setCenter(new GLatLng( , ), 11, G_NORMAL_MAP); // Creates a marker whose info window displays the given number function createMarker(point, number) { var marker = new GMarker(point); // Show this markers index in the info window when it is clicked var html = number; GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);}); return marker; };
8
透過echo的方式把圖釘點一個個產生出來
<?php $link = mysql_connect("[database server]", "[username]", "[password]") or die("Could not connect: " . mysql_error()); mysql_selectdb("[database name]",$link) or die ("Can\'t use dbmapserver : " . mysql_error()); $result = mysql_query("SELECT * FROM wholocations",$link); if (!$result) {echo "no results “;} while($row = mysql_fetch_array($result)) {echo "var point = new GLatLng(" . $row['lat'] . "," . $row['lon'] . ");\n"; echo "var marker = createMarker(point, '" . addslashes($row['description']) . "');\n"; echo "map.addOverlay(marker);\n"; echo "\n";} mysql_close($link); ?> //]]> </script> </body> </html>
10
注意~現在map api為第三版 <script src=" key]w"type="text/javascript"></script> Api有分成2,3版本,請參閱詳細文件
Similar presentations