﻿/**
 * GoogleMapを複数設置する。
 * 
 * 2008.03.03 NAKAMOTO(nakamoto@wise-p.co.jp))
 */

/* ============================================================================
 * グローバル変数
 * ============================================================================ */

//	GMap2オブジェクト格納用連想配列
var map = new Object;

//	GeoCoderクラスオブジェクト格納用
var geocoder = new GClientGeocoder();


/* ============================================================================
 * 関数
 * ============================================================================ */

/**
 * GMapオブジェクトを生成する。
 * @param integer map_id  マップ識別文字列（HTML要素のID）
 * @param string  address 住所・座標を示す文字列
 * @return void
 */
function loadMap(map_id, address) {
	//	オブジェクト生成
	if (GBrowserIsCompatible()) {
		//	オブジェクト生成
		map[map_id] = new GMap2(document.getElementById(map_id));
		
		map[map_id].addControl(new GSmallMapControl());
		
		//	位置の初期設定
		map[map_id].setCenter(new GLatLng(39.31, 137.31), 5);
		//	位置情報設定
		showAddress(map_id, address);
	}
}

/**
 * マップの位置情報を設定する。
 * @param integer map_id  マップ識別文字列（HTML要素のID）
 * @param string  address 住所・座標を示す文字列
 * @return void
 */
function showAddress(map_id, address) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					//	座標位置が判断できない場合の処理
					alert(address +
					" \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002");
					
				} else {
					//	座標位置が特定できたので設定を行う
					map[map_id].clearOverlays();
					map[map_id].setCenter(point, 16);
					var marker = new GMarker(point);
					map[map_id].addOverlay(marker);
				}
			}
		);
	}
}
