[Google Map]地圖上插上標識(GMarker)

七月 12, 2008
Tags:

GMarker

有了地圖之後就可以在上面插上像大頭針的marker。


如何知道座標

Google Maps 輸入地址(其它方式)將點移到地圖中央再按右上角的「連結至此網頁」就會出現一個網址。
例如用地址找到古亭國小會得到一組網址「http://maps.google.com/maps?f=q&hl=zh-TW&geocode=&q=%E5%8F%A4%E4%BA%AD%E5%9C%8B%E5%B0%8F&sll=25.08532,121.561498&sspn=0.323376,0.439453&ie=UTF8&ll=25.021004,121.529388& spn=0.010111,0.013733&z=16&iwloc=addr」,其中的(25.021004,121.529388)就是古亭國小的座標。

GMarker

程式碼

執行範例

google.load("maps", "2.x");
google.setOnLoadCallback(initialize);

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

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

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

function addSite(map, siteCode, siteDesc, lat, lng) {
	var mark = new GMarker(
		new GLatLng(lat,lng),
		{title:siteDesc}
		);
	map.addOverlay(mark);
}
2,024 views

 

Comments are closed.