2010年11月26日 星期五

轉錄 Google Map Api -GDownloadUrl 函式

轉路來源 Maps API Blogs

透過 GDownloadUrl可以讀取 XML 的資料轉成 javascript 所接受的格式,近接使用的話可以吧php 或 jsp 從資料庫撈出來的檔案給 javascript 好結合使用 google map api.

以下是code, 說好是 函式有個Url, 當然要吧XML和html 檔放到webser 上阿,如apache 或 tomcat 上


// Download the data in data.xml and load it on the map.

GDownloadUrl("data.xml", function(data, responseCode) {
// To ensure against HTTP errors that result in null or bad data,
// always check status code is equal to 200 before processing the data
if(responseCode == 200) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < point =" new" responsecode ="=">





X範例的ML檔


<markers>
<marker lat="37.427770" lng="-122.144841"/>
<marker lat="37.413320" lng="-122.125604"/>
<marker lat="37.433480" lng="-122.139062"/>
<marker lat="37.445427" lng="-122.162307"/>
</markers>

2010年11月22日 星期一

Google mpa api - infowindows 使用

主要流程參考 http://www.svennerberg.com/2009/09/google-maps-api-3-infowindows/


首先,先建立google map


// Creating an option object for the map
var options = {
zoom: 7,
center: new google.maps.LatLng(56.83, 15.16),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Initializing the map
var map = new google.maps.Map(document.getElementById('map'), options);
// Creating a marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(56.8848, 14.7730),
map: map,
title: 'My workplace'
});




宣告 InfoWindow(), 包含顯示的內容在 content 裡面


// Creating an InfoWindow object
var infowindow = new google.maps.InfoWindow({
content: 'Hello world'
});



增加監聽事件,點選標記後就會顯示 infowindow


google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});




Google 說明文件:
http://code.google.com/intl/zh-TW/apis/maps/documentation/javascript/overlays.html#InfoWindows

轉貼 SVN client

版本控制在軟體開發算是很重要的一部分,常見的軟體有有SVN 和 CVS.

到官方網站下載,http://tortoisesvn.net/downloads

中文化這裡 32 bit, 64bit

下載完安裝完之後 就可以重新啟動了


-------------------------------
若要在本機使用的話,

1. 先選擇一個資料夾, 假設是 C:\SVN, 好存放變動的紀錄

按滑鼠右鍵選擇「TortoiseSVN」→「Create repository here」

2. 建立一個資料夾 如 C:\testSvn\, 右鍵 svn checkout

url 的地方填入 剛剛做 server 的資料夾 ,如 file:///C:\SVN\



之後就可以使用svn 的功能了



基本上流程我是參考http://demo.tc/Post/591

若要參考server 端的安裝方式 可以看這篇 liang' blog 的文章

Google map api - marker 建立

參考自 http://www.svennerberg.com/2009/07/google-maps-api-3-markers/


在地圖上建立 標記

現在google map 已經不需要使用 API key

所以在header 上加入 如

<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", "1");</script>
<script type="text/javascript">
google.load("maps", "3", {other_params:"sensor=false"});
</script>






建立標記前 , 比須先宣告 map 物件, 記得在html 上給 map 一個 div 標籤


var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: new google.maps.LatLng(56.83, 15.16),
mapTypeId: google.maps.MapTypeId.ROADMAP
});


建立 標記marker


// Creating a marker and positioning it on the map
var marker = new google.maps.Marker({
position: new google.maps.LatLng(56.8848, 14.7730),
map: map
});



轉貼 jsp 連 mysql

架設好 tomcat 和 mysql 後 , 需要安裝 JDBC Driver 才能讓 tomcat 讀取 mysql,


JDBC driver 安裝擋案可以到 這裡 (http://dev.mysql.com/downloads/connector/j/5.0.html) 下載
下載後 將 mysql-connector-java-5.1.13-bin.jar 這個檔案 放在 tomcat 安裝目錄下的 bin 資料夾裡

當然要重新啟動才會生效





以下是修改後的測試程式,
(從 http://www.roseindia.net/jsp/connect-jsp-mysql.shtml 修改的)
在 mysql 建立 一個 test 資料庫 , 應為這裡沒設密碼 所以帳號密碼就是 "root" ,""






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<html>
<head>
<title>Connection with mysql database</title>
</head>
<body>
<h1>Connection status </h1>
<%
try {
/* Create string of connection url within specified format with machine name,
port number and database name. Here machine name id localhost and
database name is usermaster. */
String connectionURL = "jdbc:mysql://localhost:3306/test";

// declare a connection by using Connection interface
Connection connection = null;

// Load JBBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();

/* Create a connection by using getConnection() method that takes parameters of
string type connection url, user name and password to connect to database. */
connection = DriverManager.getConnection(connectionURL, "root", "");

// check weather connection is established or not by isClosed() method
if(!connection.isClosed())
%>
<span ></b>
<%
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}
catch(Exception ex){
%>
</span>
<span ></b>
<%
out.println("Unable to connect to database.");
}
%>
</span>
</body>
</html>



參考網站
http://wiki.oss.org.tw/index.php/Jsp_database

http://blog.yam.com/carl44/article/14825336