<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Horn Network &#187; Google Map</title>
	<atom:link href="http://klcin.tw/net/tag/google-map/feed" rel="self" type="application/rss+xml" />
	<link>http://klcin.tw/net</link>
	<description>Horn Network (.NET, ASP.NET, C#, VB.NET, JavaScript, Ubuntu, Android ...)</description>
	<lastBuildDate>Fri, 04 Mar 2011 07:25:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>[實例]行政院環保署-測站資訊with Google map</title>
		<link>http://klcin.tw/net/epa-sitegmap</link>
		<comments>http://klcin.tw/net/epa-sitegmap#comments</comments>
		<pubDate>Tue, 26 Aug 2008 02:43:44 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>
		<category><![CDATA[psi]]></category>
		<category><![CDATA[中央社]]></category>
		<category><![CDATA[地圖]]></category>
		<category><![CDATA[實例]]></category>
		<category><![CDATA[新聞]]></category>
		<category><![CDATA[測站資訊]]></category>
		<category><![CDATA[環保署]]></category>
		<category><![CDATA[空氣品質]]></category>
		<category><![CDATA[自由時報]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/epa-sitegmap</guid>
		<description><![CDATA[新聞稿： 住家空氣品質知多少？上網即可輕易查 2008/08/25 13:06:08 （中央社記者陳舜協台北2008年8月25日電）國人有過敏體質人數愈來愈多，加上外出旅遊、活動風氣日盛，對空氣品質的需求日益增加。鑑於國人需求，環保署環境監測及資訊處近期完成「測站資訊with Googlemap 」系統，結合Googlemap的親和界面，民眾只要輸入自家或出遊地點地址，就可輕易獲得即時空氣品質資訊。 監資處長朱雨其指出，「測站資訊with Google map」系統除提供即時空氣品質資訊，還提供最近24小時空氣品質預測及最近的空氣測站相關資料，提供民眾最符合實際需求的空氣品質資訊。 此外，監資處還新增空氣品質監測資料網路下載服務。朱雨其指出，監資處將歷年全台各測站資訊整理成套裝方式，方便民眾免費查詢、下載，以利各界分析或進行學術研究，有需要的民眾可多加利用。 自由時報＼2008/08/26＼生活新聞A8＼空氣品質 地圖e點就知 網址 http://taqm.epa.gov.tw/emc/default.aspx?mod=SiteGMap&#38;pid=b0101&#38;cid=b0102 使用技術： [Google Map]地址查詢(GClientGeocoder) [Google Map]自訂標籤圖示(GIcon) [Google Map]顯示訊息視窗[1](openInfoWindowHtml) 搭配後端測站位置及空氣品質資訊]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://klcin.tw/net/wp-content/uploads/2008/08/snap029.png"><img title="測站資訊with Googlemap" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="147" alt="測站資訊with Googlemap" src="http://klcin.tw/net/wp-content/uploads/2008/08/snap029-thumb.png" width="244" border="0" /></a></p>
<h2>新聞稿：</h2>
<blockquote><h2><a href="http://www.cna.com.tw/business/NewsDetail.aspx?strSearchDate=&amp;strNewsDate=20080825&amp;strNewsID=200808250265&amp;strNewsType=DT&amp;strNewsLev=3&amp;strType=idtNews" target="_blank">住家空氣品質知多少？上網即可輕易查</a></h2>
<p>2008/08/25 13:06:08      <br />（中央社記者陳舜協台北2008年8月25日電）國人有過敏體質人數愈來愈多，加上外出旅遊、活動風氣日盛，對空氣品質的需求日益增加。鑑於國人需求，環保署環境監測及資訊處近期完成「測站資訊with Googlemap 」系統，結合Googlemap的親和界面，民眾只要輸入自家或出遊地點地址，就可輕易獲得即時空氣品質資訊。</p>
<p>監資處長朱雨其指出，「測站資訊with Google map」系統除提供即時空氣品質資訊，還提供最近24小時空氣品質預測及最近的空氣測站相關資料，提供民眾最符合實際需求的空氣品質資訊。</p>
<p>此外，監資處還新增空氣品質監測資料網路下載服務。朱雨其指出，監資處將歷年全台各測站資訊整理成套裝方式，方便民眾免費查詢、下載，以利各界分析或進行學術研究，有需要的民眾可多加利用。</p>
</blockquote>
<p>自由時報＼2008/08/26＼生活新聞A8＼空氣品質 地圖e點就知</p>
<p align="center"><a href="http://klcin.tw/net/images/withGooglemap_129A1/200808262050_CIMG0232.jpg"><img title="自由時報" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="自由時報" src="http://klcin.tw/net/images/withGooglemap_129A1/200808262050_CIMG0232_thumb.jpg" width="220" border="0" /></a> </p>
<h2>網址</h2>
<p><a title="http://taqm.epa.gov.tw/emc/default.aspx?mod=SiteGMap&amp;pid=b0101&amp;cid=b0102" href="http://taqm.epa.gov.tw/emc/default.aspx?mod=SiteGMap&amp;pid=b0101&amp;cid=b0102">http://taqm.epa.gov.tw/emc/default.aspx?mod=SiteGMap&amp;pid=b0101&amp;cid=b0102</a></p>
</p>
<p> <span id="more-69"></span>
</p>
<h2>使用技術：</h2>
<ul>
<li><a href="http://klcin.tw/net/google-map-gclientgeocoder" target="_blank">[Google Map]地址查詢(GClientGeocoder)</a> </li>
<li><a href="http://klcin.tw/net/google-map-gicon" target="_blank">[Google Map]自訂標籤圖示(GIcon)</a> </li>
<li><a href="http://klcin.tw/net/google-map-marker-openinfowindowhtml" target="_blank">[Google Map]顯示訊息視窗[1](openInfoWindowHtml)</a> </li>
<li>搭配後端測站位置及空氣品質資訊 </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/epa-sitegmap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Google Map]以指定長度為半徑畫圖</title>
		<link>http://klcin.tw/net/google-map-circle</link>
		<comments>http://klcin.tw/net/google-map-circle#comments</comments>
		<pubDate>Fri, 22 Aug 2008 12:00:32 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=37</guid>
		<description><![CDATA[在電視電影中的連續犯罪事件，常常可以看到偵探或警方在地圖上以犯罪現場為中心依地緣關係畫出圓形而展開調查。 即然能用GPolygon畫出多邊形，加點小小的計算我們也能畫出圓形，而且是可以指定半徑距離(如5公里)的圓！ 程式碼 執行範例 google.load(&#34;maps&#34;, &#34;2.x&#34;); google.setOnLoadCallback(initialize); var map = null; function initialize() { // 檢查瀏覽器是否可使用 Google Map API if ( GBrowserIsCompatible() ) { map = new google.maps.Map2(document.getElementById(&#039;map&#039;)); // 設定地圖中心點 map.setCenter(new GLatLng(25.036772,121.520269), 10); // 畫圓！ draw(5/*半徑,公里*/, 36/*以多少點畫圓*/); } // if else { alert(&#039;您的瀏覽器不支援Google Map&#039;); } // else } ////pan and zoom to fit var bounds [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMap_E3DE/snap103.png"><img title="" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="260" alt="" src="http://klcin.tw/net/images/GoogleMap_E3DE/snap103_thumb.png" width="251" border="0" /></a> </p>
<p>在電視電影中的連續犯罪事件，常常可以看到偵探或警方在地圖上以犯罪現場為中心依地緣關係畫出圓形而展開調查。    <br />即然能用GPolygon畫出多邊形，加點小小的計算我們也能畫出圓形，而且是可以指定半徑距離(如5公里)的圓！</p>
</p>
</p>
<p> <span id="more-37"></span><br />
<h1>程式碼</h1>
<p><a href="http://klcin.tw/ap/gmap/map42.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 10);
		// 畫圓！
		draw(5/*半徑,公里*/, 36/*以多少點畫圓*/);
	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}

////pan and zoom to fit
var bounds = new GLatLngBounds();
function fit(){
	map.panTo(bounds.getCenter());
	map.setZoom(map.getBoundsZoomLevel(bounds));
}

//calling circle drawing function
function draw(givenRad, givenQuality){
	map.clearOverlays();
	bounds = new GLatLngBounds();
	var centre = map.getCenter()
	drawCircle(centre, givenRad, givenQuality);
	fit();
}

////////////////////////// circle///////////////////////////////
function drawCircle(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa)
{
// Esa 2006
	//calculating km/degree
	var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100;
	var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100;

	//Loop
	var points = [];
	var step = parseInt(360/nodes)||10;
	for(var i=0; i&lt;=360; i+=step)
	{
	var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng() +
	(radius/lngConv * Math.sin(i * Math.PI/180)));
	points.push(pint);
	bounds.extend(pint); //this is for fit function
	}
	fillColor = fillColor||liColor||&quot;#0055ff&quot;;
	liWidth = liWidth||2;
	var poly = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa);
	map.addOverlay(poly);
}</pre>
<h4>參考資料：</h4>
<ul>
<li><a href="http://esa.ilmari.googlepages.com/circle.htm">Esa&#8217;s Google Maps API examples</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-circle/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Google Map]自訂控制項 GControl</title>
		<link>http://klcin.tw/net/google-map-cust-gcontrol</link>
		<comments>http://klcin.tw/net/google-map-cust-gcontrol#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:00:32 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=38</guid>
		<description><![CDATA[將自己的元作放到地圖上。 Google API GControl : This interface is implemented by all controls. 實作這個介面。 程式碼 執行範例 function TwControl() {} TwControl.prototype = new GControl(); // 起始 TwControl.prototype.initialize = function(map) { var container = document.createElement(&#34;div&#34;); container.appendChild(this.createButton(&#34;台灣&#34;,23.639492, 120.783691, 8)); container.appendChild(this.createButton(&#34;馬祖&#34;,26.162083,119.941472, 10)); container.appendChild(this.createButton(&#34;金門&#34;,24.429333,118.315389, 10)); map.getContainer().appendChild(container); return container; } // 預設位置 TwControl.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7)); [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMapGControl_F53D/snap104.png"><img title="" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="172" alt="" src="http://klcin.tw/net/images/GoogleMapGControl_F53D/snap104_thumb.png" width="238" border="0" /></a> </p>
<p>將自己的元作放到地圖上。</p>
<p> <span id="more-38"></span><br />
<h1>Google API</h1>
<ul>
<li><a href="http://code.google.com/apis/maps/documentation/reference.html#GControl" target="_blank">GControl</a> : This interface is implemented by all controls. 實作這個介面。</li>
</ul>
<h1>程式碼</h1>
<p><a href="http://klcin.tw/ap/gmap/map50.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<pre class="brush: javascript">function TwControl() {}
TwControl.prototype = new GControl();
// 起始
TwControl.prototype.initialize = function(map) {
    var container = document.createElement(&quot;div&quot;);

    container.appendChild(this.createButton(&quot;台灣&quot;,23.639492, 120.783691, 8));
    container.appendChild(this.createButton(&quot;馬祖&quot;,26.162083,119.941472, 10));
    container.appendChild(this.createButton(&quot;金門&quot;,24.429333,118.315389, 10));

    map.getContainer().appendChild(container);
    return container;
}
// 預設位置
TwControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}
// 建立按鈕
TwControl.prototype.createButton = function(name, lat, lng, zoom) {
    var div = document.createElement(&quot;div&quot;);
    this.setButtonStyle_(div);
    div.appendChild(document.createTextNode(name));
    GEvent.addDomListener(div, &quot;click&quot;, function() {
      map.setCenter(new GLatLng(lat, lng), zoom);
    });
    return div;
}
// 設定按鈕樣式
TwControl.prototype.setButtonStyle_ = function(button) {
    button.style.textDecoration = &quot;underline&quot;;
    button.style.color = &quot;#0000cc&quot;;
    button.style.backgroundColor = &quot;white&quot;;
    button.style.font = &quot;small Arial&quot;;
    button.style.border = &quot;1px solid black&quot;;
    button.style.padding = &quot;2px&quot;;
    button.style.marginBottom = &quot;3px&quot;;
    button.style.textAlign = &quot;center&quot;;
    button.style.width = &quot;6em&quot;;
    button.style.cursor = &quot;pointer&quot;;
}

// 加入
map.addControl(new TwControl());</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-cust-gcontrol/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Google Map]畫多邊形(GPolygon)</title>
		<link>http://klcin.tw/net/google-map-gpolygon</link>
		<comments>http://klcin.tw/net/google-map-gpolygon#comments</comments>
		<pubDate>Sun, 10 Aug 2008 04:00:10 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=36</guid>
		<description><![CDATA[除了點(GMark)線(GPolyline)之後，我們還能表現面(GPolygon)！ Google API GPolygon : This is very similar to a GPolyline, except that you can additionally specify a fill color and opacity. 位置陣列中一定要封閉，即第一點和最後一點的座標要相同。 程式碼 執行範例 google.load(&#34;maps&#34;, &#34;2.x&#34;); google.setOnLoadCallback(initialize); var map = null; function initialize() { // 檢查瀏覽器是否可使用 Google Map API if ( GBrowserIsCompatible() ) { map = new google.maps.Map2(document.getElementById(&#039;map&#039;)); // 設定地圖中心點 map.setCenter(new GLatLng(25.036772,121.520269), 11); [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMapGPolygon_DFE2/snap102.png"><img title="" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="209" alt="" src="http://klcin.tw/net/images/GoogleMapGPolygon_DFE2/snap102_thumb.png" width="252" border="0" /></a> </p>
<p>除了點(GMark)線(GPolyline)之後，我們還能表現面(GPolygon)！</p>
<p> <span id="more-36"></span><br />
<h2>Google API</h2>
<ul>
<li><a href="http://code.google.com/apis/maps/documentation/reference.html#GPolygon" target="_blank">GPolygon</a> : This is very similar to a <a href="http://code.google.com/apis/maps/documentation/reference.html#GPolyline">GPolyline</a>, except that you can additionally specify a fill color and opacity.</li>
<li>位置陣列中一定要封閉，即第一點和最後一點的座標要相同。</li>
</ul>
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map41.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 11);

		var points = [];
		points.push(new GLatLng(25.030000,121.490556)); // 萬華
		points.push(new GLatLng(25.035556,121.424722)); // 新莊
		points.push(new GLatLng(25.063611,121.518056)); // 中山
		points.push(new GLatLng(24.978889,121.529167)); // 新店
		points.push(new GLatLng(25.013611,121.466667)); // 板橋
		points.push(new GLatLng(25.030000,121.490556)); // 萬華(封閉)
		// 畫多邊形
		map.addOverlay(new GPolygon(points,&#039;#FF0000&#039;,3,0.5,&#039;#ffff00&#039;,0.5));
	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-gpolygon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Google Map]畫線(GPolyline)</title>
		<link>http://klcin.tw/net/google-map-gpolyline</link>
		<comments>http://klcin.tw/net/google-map-gpolyline#comments</comments>
		<pubDate>Sat, 09 Aug 2008 04:00:38 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=35</guid>
		<description><![CDATA[除了用 mark 在地圖上標出座標外，我們還能在地圖上畫線表示路線等資訊。 Google API GPolyline : This is a map overlay that draws a polyline on the map, using the vector drawing facilities of the browser if they are available, or an image overlay from Google servers otherwise. 程式碼 執行範例：取得目前地圖的可視範圍，隨機加入10個標籤，並畫線 google.load(&#34;maps&#34;, &#34;2.x&#34;); google.setOnLoadCallback(initialize); var map = null; function initialize() { // 檢查瀏覽器是否可使用 Google Map [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMapGPolyline_DEB4/snap101.png"><img title="" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="260" alt="" src="http://klcin.tw/net/images/GoogleMapGPolyline_DEB4/snap101_thumb.png" width="257" border="0" /></a> </p>
<p>除了用 mark 在地圖上標出座標外，我們還能在地圖上畫線表示路線等資訊。</p>
<p> <span id="more-35"></span><br />
<h2>Google API</h2>
<ul>
<li><a href="http://code.google.com/apis/maps/documentation/reference.html#GPolyline" target="_blank">GPolyline</a> : This is a map overlay that draws a polyline on the map, using the vector drawing facilities of the browser if they are available, or an image overlay from Google servers otherwise. </li>
</ul>
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map40.htm" target="_blank" rel="gb_page_fs[]">執行範例</a>：取得目前地圖的可視範圍，隨機加入10個標籤，並畫線</p>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 12);

		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest(); // 返回矩形西南角的點
		var northEast = bounds.getNorthEast(); // 返回矩形東北角的點
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		var points = [];
		// 亂數取點
		for (var i = 0; i &lt; 10; i++){
		    var point = new GLatLng(
		        southWest.lat() + latSpan * Math.random(),
		        southWest.lng() + lngSpan * Math.random());
		    points.push(point);
		    map.addOverlay(new GMarker(point));
		} // for
		// 排序
		points.sort(function(p1, p2) { return p1.lng() - p2.lng();});
		// 畫線！
		map.addOverlay(new GPolyline(points));
	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-gpolyline/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Google Map]地址查詢(GClientGeocoder)</title>
		<link>http://klcin.tw/net/google-map-gclientgeocoder</link>
		<comments>http://klcin.tw/net/google-map-gclientgeocoder#comments</comments>
		<pubDate>Tue, 29 Jul 2008 10:00:21 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=34</guid>
		<description><![CDATA[地圖雖然可以隨意拖拉，但全世界那麼多怎樣才能最快找到目標呢？直接輸入地址查詢！ Google API GClientGeocoder : This class is used to communicate directly with Google servers to obtain geocodes for user specified addresses. In addition, a geocoder maintains its own cache of addresses, which allows repeated queries to be answered without a round trip to the server. .getLocations( address , callback ) 查詢地址。 callback (result) result.Status.code [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMapGClientGeocoder_D70B/snap100.png"><img title="" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="243" alt="" src="http://klcin.tw/net/images/GoogleMapGClientGeocoder_D70B/snap100_thumb.png" width="361" border="0" /></a> </p>
<p>地圖雖然可以隨意拖拉，但全世界那麼多怎樣才能最快找到目標呢？直接輸入地址查詢！</p>
<p> <span id="more-34"></span><br />
<h2>Google API</h2>
<ul>
<li><a href="http://code.google.com/apis/maps/documentation/reference.html#GClientGeocoder" target="_blank">GClientGeocoder</a> : This class is used to communicate directly with Google servers to obtain geocodes for user specified addresses. In addition, a geocoder maintains its own cache of addresses, which allows repeated queries to be answered without a round trip to the server.</li>
<ul>
<li>.getLocations( address , callback ) 查詢地址。</li>
</ul>
<li>callback (result)</li>
<ul>
<li>result.Status.code == G_GEO_SUCCESS ： 判斷是否成功。</li>
<li>result.Placemark.length ： 符合條件的位置數。</li>
<li>result.Placemark[i].Point.coordinates[0]; ： lng</li>
<li>result.Placemark[i].Point.coordinates[1]; ： lat</li>
<li>result.Placemark[i].address; ： 地址</li>
</ul>
</ul>
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map10.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
var geocoder = null;
function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		geocoder = new GClientGeocoder();

		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 12);
	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}

function showLocation() {
	// 清除marker
	map.clearOverlays();
	var address = document.getElementById(&#039;txtAddress&#039;).value;
	geocoder.getLocations(address, cb_showLocation);
}

function cb_showLocation(result) {
	// 顯示結果
	if (result.Status.code == G_GEO_SUCCESS)  {
		// 成功
		for (var i=0; i&lt;result.Placemark.length; i++) {
			var lat = result.Placemark[i].Point.coordinates[1]; // lat
			var lng = result.Placemark[i].Point.coordinates[0]; // lng
			var address = result.Placemark[i].address; // 地址
			var point = new GLatLng(lat,lng);

			var marker=new GMarker(point, {title:i+1});;
			map.addOverlay(marker);
		} // for
	} // if
}

var status=[];
status[G_GEO_SUCCESS]            = &quot;Success&quot;;
status[G_GEO_MISSING_ADDRESS]    = &quot;Missing Address&quot;;
status[G_GEO_UNKNOWN_ADDRESS]    = &quot;Unknown Address&quot;;
status[G_GEO_UNAVAILABLE_ADDRESS]= &quot;Unavailable Address&quot;;
status[G_GEO_BAD_KEY]            = &quot;Bad Key&quot;;
status[G_GEO_TOO_MANY_QUERIES]   = &quot;Too Many Queries&quot;;
status[G_GEO_SERVER_ERROR]       = &quot;Server Error&quot;;</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-gclientgeocoder/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>[Google Map]GMark事件運用(GEvent)</title>
		<link>http://klcin.tw/net/google-map-gevent</link>
		<comments>http://klcin.tw/net/google-map-gevent#comments</comments>
		<pubDate>Sat, 19 Jul 2008 10:00:03 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=15</guid>
		<description><![CDATA[透過GEvent，我們可以讓地圖上的物件與網頁元作互動，達到對使用者更友善的介面。 如本範例，當滑鼠移過(moveover)右側的站名方塊時地圖中對應的marker會變紅色，點(click)方塊時地圖會顯示訊息視窗。 若滑鼠移過(moveover)地圖中的marker相對應的站名方塊也會變黃底突顯。 當地圖內marker太多時這個技巧特別有用。 GEvent GEvent .addListener .trigger 觸發地圖內的事件 程式碼 執行範例 javascript google.load(&#34;maps&#34;, &#34;2.x&#34;); google.setOnLoadCallback(initialize); var map = null; var arySite = new Array(); function initialize() { // 檢查瀏覽器是否可使用 Google Map API if ( GBrowserIsCompatible() ) { map = new google.maps.Map2(document.getElementById(&#039;map&#039;)); // 設定地圖中心點 map.setCenter(new GLatLng(25.036772,121.520269), 12); addSite(map,4,&#039;新店&#039;,24.978889,121.529167,&#039;台北縣新店市三民路36號&#039;,40,23,&#039;懸浮微粒&#039;,0); addSite(map,5,&#039;土城&#039;,24.981667,121.451667,&#039;台北縣土城市學府路一段241號&#039;,40,26,&#039;懸浮微粒&#039;,0); addSite(map,6,&#039;板橋&#039;,25.012778,121.459167,&#039;台北縣板橋市文化路一段25號&#039;,40,27,&#039;懸浮微粒&#039;,0); addSite(map,7,&#039;新莊&#039;,25.034056,121.432583,&#039;台北縣新莊市中正路510號&#039;,40,27,&#039;臭氧&#039;,0); addSite(map,8,&#039;菜寮&#039;,25.064167,121.480556,&#039;台北縣三重市中正北路135號&#039;,40,26,&#039;懸浮微粒&#039;,0); addSite(map,9,&#039;林口&#039;,25.078333,121.368611,&#039;台北縣林口鄉民治路25號&#039;,40,26,&#039;臭氧&#039;,0); addSite(map,10,&#039;淡水&#039;,25.164694,121.449139,&#039;台北縣淡水鎮中正東路42巷6號&#039;,40,21,&#039;懸浮微粒&#039;,0); addSite(map,11,&#039;士林&#039;,25.105389,121.515139,&#039;台北市北投區文林北路155號&#039;,40,37,&#039;懸浮微粒&#039;,0); addSite(map,12,&#039;中山&#039;,25.062361,121.526194,&#039;台北市中山區林森北路511號&#039;,40,28,&#039;懸浮微粒&#039;,0); [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMapGMarkGEvent_E146/snap082.png"><img title="" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="163" alt="" src="http://klcin.tw/net/images/GoogleMapGMarkGEvent_E146/snap082_thumb.png" width="260" border="0" /></a> </p>
<p>透過GEvent，我們可以讓地圖上的物件與網頁元作互動，達到對使用者更友善的介面。</p>
<p>如本範例，當滑鼠移過(moveover)右側的站名方塊時地圖中對應的marker會變紅色，點(click)方塊時地圖會顯示訊息視窗。    <br />若滑鼠移過(moveover)地圖中的marker相對應的站名方塊也會變黃底突顯。     <br />當地圖內marker太多時這個技巧特別有用。</p>
<p> <span id="more-15"></span><br />
<h2>GEvent</h2>
<ul>
<li><a href="http://code.google.com/apis/maps/documentation/reference.html#GEvent" target="_blank">GEvent</a>
<ul>
<li>.addListener </li>
<li>.trigger 觸發地圖內的事件 </li>
</ul>
</li>
</ul>
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map04.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<h3>javascript</h3>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
var arySite = new Array();

function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 12);

addSite(map,4,&#039;新店&#039;,24.978889,121.529167,&#039;台北縣新店市三民路36號&#039;,40,23,&#039;懸浮微粒&#039;,0);
addSite(map,5,&#039;土城&#039;,24.981667,121.451667,&#039;台北縣土城市學府路一段241號&#039;,40,26,&#039;懸浮微粒&#039;,0);
addSite(map,6,&#039;板橋&#039;,25.012778,121.459167,&#039;台北縣板橋市文化路一段25號&#039;,40,27,&#039;懸浮微粒&#039;,0);
addSite(map,7,&#039;新莊&#039;,25.034056,121.432583,&#039;台北縣新莊市中正路510號&#039;,40,27,&#039;臭氧&#039;,0);
addSite(map,8,&#039;菜寮&#039;,25.064167,121.480556,&#039;台北縣三重市中正北路135號&#039;,40,26,&#039;懸浮微粒&#039;,0);
addSite(map,9,&#039;林口&#039;,25.078333,121.368611,&#039;台北縣林口鄉民治路25號&#039;,40,26,&#039;臭氧&#039;,0);
addSite(map,10,&#039;淡水&#039;,25.164694,121.449139,&#039;台北縣淡水鎮中正東路42巷6號&#039;,40,21,&#039;懸浮微粒&#039;,0);
addSite(map,11,&#039;士林&#039;,25.105389,121.515139,&#039;台北市北投區文林北路155號&#039;,40,37,&#039;懸浮微粒&#039;,0);
addSite(map,12,&#039;中山&#039;,25.062361,121.526194,&#039;台北市中山區林森北路511號&#039;,40,28,&#039;懸浮微粒&#039;,0);
addSite(map,13,&#039;萬華&#039;,25.030000,121.490556,&#039;台北市萬華區莒光路315號&#039;,40,22,&#039;懸浮微粒&#039;,0);
addSite(map,14,&#039;古亭&#039;,25.020833,121.528611,&#039;台北市中正區羅斯福路三段153號&#039;,40,30,&#039;懸浮微粒&#039;,0);
addSite(map,15,&#039;松山&#039;,25.050833,121.578889,&#039;台北市松山區八德路四段746號&#039;,40,23,&#039;懸浮微粒&#039;,0);

	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}

function addSite(map, siteCode, siteDesc, lat, lng, address, type) {
	var icon=new GIcon();
	icon.image=&quot;images/1.gif&quot;;
	icon.iconSize = new GSize(16,16);
	icon.iconAnchor = new GPoint(8,8);
	icon.infoWindowAnchor = new GPoint(8, 8);

	var mark = new GMarker(
		new GLatLng(lat,lng),
		{icon:icon, title:siteDesc}
		);

	arySite[siteCode] = mark;
	map.addOverlay(mark);
	GEvent.addListener(mark, &quot;click&quot;, function() {mark.openInfoWindowHtml(&#039;測站：&#039;+siteDesc+&#039;&lt;br /&gt;地址：&#039;+address);});
	GEvent.addListener(mark, &quot;mouseover&quot;, function() {
		mark.setImage(&#039;images/1r.gif&#039;);
		document.getElementById(&#039;site&#039;+siteCode).style.background=&#039;yellow&#039;;
		});
	GEvent.addListener(mark, &quot;mouseout&quot;, function() {
		mark.setImage(&#039;images/1.gif&#039;);
		document.getElementById(&#039;site&#039;+siteCode).style.background=&#039;white&#039;;
		});
}</pre>
<h2>html</h2>
<pre class="brush: html">&lt;span class=&#039;site&#039; id=&#039;site4&#039;
	onclick=&#039;GEvent.trigger(arySite[4],&quot;click&quot;)&#039;
	onmouseover=&#039;GEvent.trigger(arySite[4],&quot;mouseover&quot;)&#039;
	onmouseout=&#039;GEvent.trigger(arySite[4],&quot;mouseout&quot;)&#039;&gt;新店
&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site5&#039; onclick=&#039;GEvent.trigger(arySite[5],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[5],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[5],&quot;mouseout&quot;)&#039;&gt;土城&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site6&#039; onclick=&#039;GEvent.trigger(arySite[6],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[6],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[6],&quot;mouseout&quot;)&#039;&gt;板橋&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site7&#039; onclick=&#039;GEvent.trigger(arySite[7],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[7],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[7],&quot;mouseout&quot;)&#039;&gt;新莊&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site8&#039; onclick=&#039;GEvent.trigger(arySite[8],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[8],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[8],&quot;mouseout&quot;)&#039;&gt;菜寮&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site9&#039; onclick=&#039;GEvent.trigger(arySite[9],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[9],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[9],&quot;mouseout&quot;)&#039;&gt;林口&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site10&#039; onclick=&#039;GEvent.trigger(arySite[10],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[10],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[10],&quot;mouseout&quot;)&#039;&gt;淡水&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site11&#039; onclick=&#039;GEvent.trigger(arySite[11],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[11],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[11],&quot;mouseout&quot;)&#039;&gt;士林&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site12&#039; onclick=&#039;GEvent.trigger(arySite[12],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[12],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[12],&quot;mouseout&quot;)&#039;&gt;中山&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site13&#039; onclick=&#039;GEvent.trigger(arySite[13],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[13],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[13],&quot;mouseout&quot;)&#039;&gt;萬華&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site14&#039; onclick=&#039;GEvent.trigger(arySite[14],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[14],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[14],&quot;mouseout&quot;)&#039;&gt;古亭&lt;/span&gt;
&lt;span class=&#039;site&#039; id=&#039;site15&#039; onclick=&#039;GEvent.trigger(arySite[15],&quot;click&quot;)&#039; onmouseover=&#039;GEvent.trigger(arySite[15],&quot;mouseover&quot;)&#039; onmouseout=&#039;GEvent.trigger(arySite[15],&quot;mouseout&quot;)&#039;&gt;松山&lt;/span&gt;
</pre>
<h4>參考資料：</h4>
<ul>
<li><small><a href="http://esa.ilmari.googlepages.com/ZMarker2.htm">Esa&#8217;s Google Maps API experiments. ZMarker with color switching</a></small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-gevent/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Google Map]標籤加文字[2](ELabel)＋計算距離</title>
		<link>http://klcin.tw/net/google-map-elabel</link>
		<comments>http://klcin.tw/net/google-map-elabel#comments</comments>
		<pubDate>Fri, 18 Jul 2008 10:00:45 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=17</guid>
		<description><![CDATA[這是另一種標籤加文字的方式。 覆寫 GOverlay 的 ELabel#1。 本文同時示範如何計算兩點間的距離。 計算距離 distanceFrom // 計算某一點距離台北火車站多遠 function distanceFrom(latlng) { var TS = new GLatLng(25.048708,121.516128); // 台北火車站 var dist=TS.distanceFrom(latlng); // 距離 dist=dist.toFixed(0)+&#34;m&#34;; // 公尺 if(parseInt(dist)&#62;10000) { // 若大於10公里則顯示為公里 dist=(parseInt(dist)/1000).toFixed(1)+&#34;km&#34;; } return dist; } 程式碼 執行範例 ELabel // http://koti.mbnet.fi/ojalesa/exam/elabel.js // Version 0.2 the .copy() parameters were wrong // version 1.0 added .show() .hide() [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://klcin.tw/net/images/GoogleMap2ELabel_E7C5/snap085.png"><img title="" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="252" alt="" src="http://klcin.tw/net/images/GoogleMap2ELabel_E7C5/snap085_thumb.png" width="260" border="0" /></a> </p>
<p>這是另一種標籤加文字的方式。 覆寫 <a href="http://code.google.com/apis/maps/documentation/reference.html#GOverlay" target="_blank">GOverlay</a> 的 ELabel<sup>#1</sup>。    <br />本文同時示範如何計算兩點間的距離。</p>
<p>  <span id="more-17"></span><br />
<h2>計算距離</h2>
<p>distanceFrom</p>
<pre class="brush: javascript">// 計算某一點距離台北火車站多遠
function distanceFrom(latlng) {
	var TS = new GLatLng(25.048708,121.516128); // 台北火車站
	var dist=TS.distanceFrom(latlng); // 距離
	dist=dist.toFixed(0)+&quot;m&quot;; // 公尺
	if(parseInt(dist)&gt;10000) {
		// 若大於10公里則顯示為公里
		dist=(parseInt(dist)/1000).toFixed(1)+&quot;km&quot;;
	}
	return dist;
}</pre>
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map06.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<h3>ELabel</h3>
<pre class="brush: javascript">// http://koti.mbnet.fi/ojalesa/exam/elabel.js
// Version 0.2      the .copy() parameters were wrong
// version 1.0      added .show() .hide() .setContents() .setPoint() .setOpacity() .overlap
function ELabel(point, html, classname, pixelOffset, percentOpacity, overlap) {
	// Mandatory parameters
	this.point = point;
	this.html = html;

	// Optional parameters
	this.classname = classname||&quot;&quot;;
	this.pixelOffset = pixelOffset||new GSize(0,0);
	if (percentOpacity) {
	  if(percentOpacity&lt;0){percentOpacity=0;}
	  if(percentOpacity&gt;100){percentOpacity=100;}
	}
	this.percentOpacity = percentOpacity;
	this.overlap=overlap||false;
} 

ELabel.prototype = new GOverlay();

ELabel.prototype.initialize = function(map) {
	var div = document.createElement(&quot;div&quot;);
	div.style.position = &quot;absolute&quot;;
	div.innerHTML = &#039;&lt;div class=&quot;&#039; + this.classname + &#039;&quot;&gt;&#039; + this.html + &#039;&lt;/div&gt;&#039; ;
	map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
	if (this.percentOpacity) {
	  if(typeof(div.style.filter)==&#039;string&#039;)
		{div.style.filter=&#039;alpha(opacity:&#039;+this.percentOpacity+&#039;)&#039;;}
	  if(typeof(div.style.KHTMLOpacity)==&#039;string&#039;)
		{div.style.KHTMLOpacity=this.percentOpacity/100;}
	  if(typeof(div.style.MozOpacity)==&#039;string&#039;)
		{div.style.MozOpacity=this.percentOpacity/100;}
	  if(typeof(div.style.opacity)==&#039;string&#039;)
		{div.style.opacity=this.percentOpacity/100;}
	}
	if (this.overlap) {
	  var z = GOverlay.getZIndex(this.point.lat());
	  this.div_.style.zIndex = z;
	}
}

ELabel.prototype.remove = function() {
	this.div_.parentNode.removeChild(this.div_);
}

ELabel.prototype.copy = function() {
	return new ELabel(this.point, this.html, this.classname,
	this.pixelOffset, this.percentOpacity, this.overlap);
}

ELabel.prototype.redraw = function(force) {
	var p = this.map_.fromLatLngToDivPixel(this.point);
	var h = parseInt(this.div_.clientHeight);
	this.div_.style.left = (p.x + this.pixelOffset.width) + &quot;px&quot;;
	this.div_.style.top = (p.y +this.pixelOffset.height - h) + &quot;px&quot;;
}

ELabel.prototype.show = function() {
	this.div_.style.display=&quot;&quot;;
}

ELabel.prototype.hide = function() {
	this.div_.style.display=&quot;none&quot;;
}

ELabel.prototype.setContents = function(html) {
	this.html = html;
	this.div_.innerHTML = &#039;&lt;div class=&quot;&#039; + this.classname + &#039;&quot;&gt;&#039; + this.html + &#039;&lt;/div&gt;&#039; ;
	this.redraw(true);
}

ELabel.prototype.setPoint = function(point) {
	this.point = point;
	if (this.overlap) {
	  var z = GOverlay.getZIndex(this.point.lat());
	  this.div_.style.zIndex = z;
	}
	this.redraw(true);
}

ELabel.prototype.setOpacity = function(percentOpacity) {
	if (percentOpacity) {
	  if(percentOpacity&lt;0){percentOpacity=0;}
	  if(percentOpacity&gt;100){percentOpacity=100;}
	}
	this.percentOpacity = percentOpacity;
	if (this.percentOpacity) {
	  if(typeof(this.div_.style.filter)==&#039;string&#039;)
		{this.div_.style.filter=&#039;alpha(opacity:&#039;+this.percentOpacity+&#039;)&#039;;}
	  if(typeof(this.div_.style.KHTMLOpacity)==&#039;string&#039;)
		{this.div_.style.KHTMLOpacity=this.percentOpacity/100;}
	  if(typeof(this.div_.style.MozOpacity)==&#039;string&#039;)
		{this.div_.style.MozOpacity=this.percentOpacity/100;}
	  if(typeof(this.div_.style.opacity)==&#039;string&#039;)
		{this.div_.style.opacity=this.percentOpacity/100;}
	}
}</pre>
<h3>javascript</h3>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;

function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		map.setMapType(G_SATELLITE_MAP);
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 12);

addSite(map,12,&#039;中山&#039;,25.062361,121.526194);
addSite(map,13,&#039;萬華&#039;,25.030000,121.490556);
addSite(map,14,&#039;古亭&#039;,25.020833,121.528611);

	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}

function addSite(map, siteCode, siteDesc, lat, lng) {
	var latlng = new GLatLng(lat,lng);
	var mark = new GMarker(latlng,{title:siteDesc,draggable:true});
	map.addOverlay(mark);

	// point, html, classname, pixelOffset, percentOpacity, overlap
	var label = new ELabel(latlng, siteDesc+&quot;(draggable)&quot;,&quot;labelstyle&quot;,new GSize(2,20),80);
	map.addOverlay(label);

	GEvent.addListener(mark,&quot;drag&quot;,function(){
		label.setPoint(mark.getPoint());

		var TS = new GLatLng(25.048708,121.516128);
		var dist=TS.distanceFrom(mark.getPoint());
		dist=dist.toFixed(0)+&quot;m&quot;;
		if(parseInt(dist)&gt;10000){dist=(parseInt(dist)/1000).toFixed(1)+&quot;km&quot;;}
		label.setContents(siteDesc+&quot;(&quot;+dist+&quot;)&quot;);
	});
}</pre>
<h4>參考資料：</h4>
<ol>
<li><small><a href="http://koti.mbnet.fi/ojalesa/exam/ruler.html">Esa&#8217;s Google Maps API examples</a></small> </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-elabel/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[Google Map]標籤加文字[1](LabeledMarker)</title>
		<link>http://klcin.tw/net/google-map-labeledmarker</link>
		<comments>http://klcin.tw/net/google-map-labeledmarker#comments</comments>
		<pubDate>Thu, 17 Jul 2008 10:00:18 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=16</guid>
		<description><![CDATA[標籤除了用圖之外還能加文字嗎？可以！ 覆寫 GMarker 的 LabeledMarker#1 讓你不用為每個地點製作特別做一張圖示！ 程式碼 執行範例 LabeledMarker // http://googlemapsbook.com/2007/01/22/extending-gmarker/ /* Constructor for an extended Marker class */ function LabeledMarker(latlng, options){ this.latlng = latlng; this.labelText = options.labelText &#124;&#124; &#34;&#34;; this.labelClass = options.labelClass &#124;&#124; &#34;markerLabel&#34;; this.labelOffset = options.labelOffset &#124;&#124; new GSize(0, 0); GMarker.apply(this, arguments); } /* It&#039;s a limitation of JavaScript inheritance that we can&#039;t [...]]]></description>
			<content:encoded><![CDATA[</p>
<p><a href="http://klcin.tw/net/images/GoogleMapLabeledMarker_E4C5/snap083.png"><img title="" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="162" alt="" src="http://klcin.tw/net/images/GoogleMapLabeledMarker_E4C5/snap083_thumb.png" width="204" border="0" /></a> </p>
<p>標籤除了用圖之外還能加文字嗎？可以！    <br />覆寫 GMarker 的 LabeledMarker<sup>#1</sup> 讓你不用為每個地點製作特別做一張圖示！</p>
<p><span id="more-16"></span><br />
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map05.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<h3>LabeledMarker</h3>
<pre class="brush: javascript">// http://googlemapsbook.com/2007/01/22/extending-gmarker/
/* Constructor for an extended Marker class */
function LabeledMarker(latlng, options){
    this.latlng = latlng;
    this.labelText = options.labelText || &quot;&quot;;
    this.labelClass = options.labelClass || &quot;markerLabel&quot;;
    this.labelOffset = options.labelOffset || new GSize(0, 0);
    GMarker.apply(this, arguments);
}

/* It&#039;s a limitation of JavaScript inheritance that we can&#039;t conveniently
   extend GMarker without having to run its constructor. In order for the
   constructor to run, it requires some dummy GLatLng. */
LabeledMarker.prototype = new GMarker(new GLatLng(0, 0));

// Creates the text div that goes over the marker.
LabeledMarker.prototype.initialize = function(map) {
	// Do the GMarker constructor first.
	GMarker.prototype.initialize.call(this, map);

	var div = document.createElement(&quot;div&quot;);
	div.className = this.labelClass;
	div.innerHTML = this.labelText;
	div.style.position = &quot;absolute&quot;;
	map.getPane(G_MAP_MARKER_PANE).appendChild(div);

	this.map = map;
	this.div = div;
}

// Redraw the rectangle based on the current projection and zoom level
LabeledMarker.prototype.redraw = function(force) {
	GMarker.prototype.redraw.call(this, map);

	// We only need to do anything if the coordinate system has changed
	if (!force) return;

	// Calculate the DIV coordinates of two opposite corners of our bounds to
	// get the size and position of our rectangle
	var p = this.map.fromLatLngToDivPixel(this.latlng);
	var z = GOverlay.getZIndex(this.latlng.lat());

	// Now position our DIV based on the DIV coordinates of our bounds
	this.div.style.left = (p.x + this.labelOffset.width) + &quot;px&quot;;
	this.div.style.top = (p.y + this.labelOffset.height) + &quot;px&quot;;
	this.div.style.zIndex = z + 1; // in front of the marker
}

// Remove the main DIV from the map pane
LabeledMarker.prototype.remove = function() {
  this.div.parentNode.removeChild(this.div);
  this.div = null;
  GMarker.prototype.remove.call(this);
}</pre>
<h3>javascript</h3>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
var arySite = new Array();

function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 11);

addSiteX(map,6,&#039;板橋&#039;,25.012778,121.459167,&#039;台北縣板橋市文化路一段25號&#039;,40,27,&#039;懸浮微粒&#039;,0);
addSiteX(map,10,&#039;淡水&#039;,25.164694,121.449139,&#039;台北縣淡水鎮中正東路42巷6號&#039;,40,21,&#039;懸浮微粒&#039;,0);
addSiteX(map,14,&#039;古亭&#039;,25.020833,121.528611,&#039;台北市中正區羅斯福路三段153號&#039;,40,30,&#039;懸浮微粒&#039;,0);

	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}

function addSiteX(map, siteCode, siteDesc, lat, lng, address, type) {
	var icon=new GIcon();
	icon.image=&quot;images/red-marker.png&quot;;
	icon.iconSize = new GSize(32, 32);
	icon.iconAnchor = new GPoint(16, 16);
	opts = {
		&quot;icon&quot;: icon,
		&quot;clickable&quot;: false,
		&quot;draggable&quot;: false,
		&quot;labelText&quot;: siteDesc,
		&quot;labelOffset&quot;: new GSize(-16, -16)
	};
	var mark = new LabeledMarker(new GLatLng(lat, lng), opts); 

	arySite[siteCode] = mark;
	map.addOverlay(mark);

	mark.div.onclick = function() {alert(&#039;測站：&#039;+siteDesc+&#039;\n地址：&#039;+address);};
}</pre>
<h4>參考資料：</h4>
<ol>
<li><small><a href="http://googlemapsbook.com/2007/01/22/extending-gmarker/">Extending The API To Create Labeled Markers at Beginning Google Maps Applications</a></small></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-labeledmarker/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[Google Map]自訂標籤圖示(GIcon)</title>
		<link>http://klcin.tw/net/google-map-gicon</link>
		<comments>http://klcin.tw/net/google-map-gicon#comments</comments>
		<pubDate>Wed, 16 Jul 2008 10:00:44 +0000</pubDate>
		<dc:creator>klcintw</dc:creator>
				<category><![CDATA[Google Map]]></category>

		<guid isPermaLink="false">http://klcin.tw/net/?p=14</guid>
		<description><![CDATA[如果我們能在地圖上標上加油站之類的圖示就能更直覺的表達訊息。 GIcon GIcon 標籤的圖示 .image 圖示的網址 .iconSize 大小，如 new GSize(16,16) .iconAnchor 定位，如 new GPoint(8,8) .infoWindowAnchor 訊息視窗定位，如 new GPoint(8, 8) 若沒有指定會無法顯示訊息視窗 程式碼 執行範例 google.load(&#34;maps&#34;, &#34;2.x&#34;); google.setOnLoadCallback(initialize); var map = null; function initialize() { // 檢查瀏覽器是否可使用 Google Map API if ( GBrowserIsCompatible() ) { map = new google.maps.Map2(document.getElementById(&#039;map&#039;)); // 設定地圖中心點 map.setCenter(new GLatLng(25.036772,121.520269), 12); addSite(map,12,&#039;中山&#039;,25.062361,121.526194,&#039;台北市中山區林森北路511號&#039;,1); addSite(map,13,&#039;萬華&#039;,25.030000,121.490556,&#039;台北市萬華區莒光路315號&#039;,2); addSite(map,14,&#039;古亭&#039;,25.020833,121.528611,&#039;台北市中正區羅斯福路三段153號&#039;,3); } [...]]]></description>
			<content:encoded><![CDATA[</p>
<p><a href="http://klcin.tw/net/images/GoogleMapGIcon_DCC8/snap081.png"><img title="" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="222" alt="" src="http://klcin.tw/net/images/GoogleMapGIcon_DCC8/snap081_thumb.png" width="195" border="0" /></a> </p>
<p>如果我們能在地圖上標上加油站之類的圖示就能更直覺的表達訊息。</p>
<p><span id="more-14"></span></p>
<h2>GIcon</h2>
<ul>
<li><a href="http://code.google.com/apis/maps/documentation/reference.html#GIcon" target="_blank">GIcon</a> 標籤的圖示
<ul>
<li>.image 圖示的網址 </li>
<li>.iconSize 大小，如 new GSize(16,16) </li>
<li>.iconAnchor 定位，如 new GPoint(8,8) </li>
<li>.infoWindowAnchor 訊息視窗定位，如 new GPoint(8, 8)          <br />若沒有指定會無法顯示訊息視窗 </li>
</ul>
</li>
</ul>
<h2>程式碼</h2>
<p><a href="http://klcin.tw/ap/gmap/map03.htm" target="_blank" rel="gb_page_fs[]">執行範例</a></p>
<pre class="brush: javascript">google.load(&quot;maps&quot;, &quot;2.x&quot;);
google.setOnLoadCallback(initialize);

var map = null;
function initialize() {
	// 檢查瀏覽器是否可使用 Google Map API
	if ( GBrowserIsCompatible() ) {
        map = new google.maps.Map2(document.getElementById(&#039;map&#039;));
		// 設定地圖中心點
		map.setCenter(new GLatLng(25.036772,121.520269), 12);

addSite(map,12,&#039;中山&#039;,25.062361,121.526194,&#039;台北市中山區林森北路511號&#039;,1);
addSite(map,13,&#039;萬華&#039;,25.030000,121.490556,&#039;台北市萬華區莒光路315號&#039;,2);
addSite(map,14,&#039;古亭&#039;,25.020833,121.528611,&#039;台北市中正區羅斯福路三段153號&#039;,3);

	} // if
	else {
		alert(&#039;您的瀏覽器不支援Google Map&#039;);
	} // else
}

function addSite(map, siteCode, siteDesc, lat, lng, address, type) {
	var icon=new GIcon();
	icon.image=&quot;images/&quot;+type+&quot;.gif&quot;;
	icon.iconSize = new GSize(16,16);
	icon.iconAnchor = new GPoint(8,8);
	icon.infoWindowAnchor = new GPoint(8, 8);

	var mark = new GMarker(
		new GLatLng(lat,lng),
		{icon:icon, title:siteDesc}
		);
	map.addOverlay(mark);
	GEvent.addListener(mark, &quot;click&quot;, function() {mark.openInfoWindowHtml(&#039;地址：&#039;+address);});
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://klcin.tw/net/google-map-gicon/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

