var currentInfoWindow = null;     //最後に開いた情報ウィンドウを記憶
var geocoder;
var map_canvas;
var initPos;
var map_Point_Y;
var map_Point_X;
var bounds;
function initialize() {
	geocoder = new google.maps.Geocoder();
	//地図初期化
	initPos = new google.maps.LatLng(37.900747, 139.049799);
	var myOptions = {
		center : initPos,
		zoom : 15,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map_canvas = new google.maps.Map(document.getElementById("map"), myOptions);
	setMarker();
}
function setMarker() {
	var bounds = new google.maps.LatLngBounds();
	var sai = "0.1";
	var minLat = parseFloat(map_Point_X) - parseFloat(sai);
	var minLon = parseFloat(map_Point_Y) - parseFloat(sai);
	var maxLat = parseFloat(map_Point_X) + parseFloat(sai);
	var maxLon = parseFloat(map_Point_Y) + parseFloat(sai);
	var cnt = 0;
	var $tmplon = "";
	var $tmplon = "";
	cnt = cnt+1;
var markerPos0 = new google.maps.LatLng("38.192721", "139.4362");
createMarker(map_canvas, markerPos0, "
井伊歯科医院村上市岩船上大町2-8
TEL 0254-56-7204
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.192721", "139.4362"));
cnt = cnt+1;
var markerPos1 = new google.maps.LatLng("38.265031", "139.568216");
createMarker(map_canvas, markerPos1, "小田歯科医院村上市布部3138
TEL 0254-72-1174
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.265031", "139.568216"));
cnt = cnt+1;
var markerPos2 = new google.maps.LatLng("38.228251", "139.491339");
createMarker(map_canvas, markerPos2, "おおしま歯科医院村上市上片町3-30
TEL 0254-53-2417
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.228251", "139.491339"));
cnt = cnt+1;
var markerPos3 = new google.maps.LatLng("38.190152", "139.437683");
createMarker(map_canvas, markerPos3, "佐久間歯科医院村上市岩船上町4-30
TEL 0254-56-7700
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.190152", "139.437683"));
cnt = cnt+1;
var markerPos4 = new google.maps.LatLng("38.103434", "139.427221");
createMarker(map_canvas, markerPos4, "鈴木歯科医院村上市長政253
TEL 0254-62-3040
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.103434", "139.427221"));
cnt = cnt+1;
var markerPos5 = new google.maps.LatLng("38.226898", "139.486862");
createMarker(map_canvas, markerPos5, "滝沢歯科医院村上市堀片3-23
TEL 0254-52-3003
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.226898", "139.486862"));
cnt = cnt+1;
var markerPos6 = new google.maps.LatLng("38.228433", "139.46005");
createMarker(map_canvas, markerPos6, "堀田歯科医院村上市学校町3-50
TEL 0254-53-1238
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.228433", "139.46005"));
cnt = cnt+1;
var markerPos7 = new google.maps.LatLng("38.184114", "139.457165");
createMarker(map_canvas, markerPos7, "藤原歯科診療所村上市岩船駅前30-8
TEL 0254-56-6393
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.184114", "139.457165"));
cnt = cnt+1;
var markerPos8 = new google.maps.LatLng("38.217649", "139.451871");
createMarker(map_canvas, markerPos8, "村井歯科医院村上市松山259-5
TEL 0254-52-3684
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.217649", "139.451871"));
cnt = cnt+1;
var markerPos9 = new google.maps.LatLng("38.221896", "139.465709");
createMarker(map_canvas, markerPos9, "本間歯科医院村上市田端町13-30
TEL 0254-52-2690
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.221896", "139.465709"));
cnt = cnt+1;
var markerPos10 = new google.maps.LatLng("38.226467", "139.477532");
createMarker(map_canvas, markerPos10, "高原歯科医院村上市塩町1-15
TEL 0254-52-2309
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.226467", "139.477532"));
cnt = cnt+1;
var markerPos11 = new google.maps.LatLng("38.122633", "139.45022");
createMarker(map_canvas, markerPos11, "前川歯科クリニック村上市羽ケ榎185-1
TEL 0254-62-2867
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.122633", "139.45022"));
cnt = cnt+1;
var markerPos12 = new google.maps.LatLng("38.219004", "139.457562");
createMarker(map_canvas, markerPos12, "緑町歯科クリニック村上市緑町4-2-73
TEL 0254-53-6677
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.219004", "139.457562"));
cnt = cnt+1;
var markerPos13 = new google.maps.LatLng("38.1144017", "139.4447851");
createMarker(map_canvas, markerPos13, "あらかわ歯科クリニック村上市坂町1569-2
TEL 0254-62-1717
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.1144017", "139.4447851"));
cnt = cnt+1;
var markerPos14 = new google.maps.LatLng("38.220465", "139.469853");
createMarker(map_canvas, markerPos14, "中野歯科医院村上市飯野3-10-11
TEL 0254-53-7500
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.220465", "139.469853"));
cnt = cnt+1;
var markerPos15 = new google.maps.LatLng("38.513552", "139.532241");
createMarker(map_canvas, markerPos15, "本図歯科医院村上市府屋176-143
TEL 0254-77-2473
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.513552", "139.532241"));
cnt = cnt+1;
var markerPos16 = new google.maps.LatLng("38.221479", "139.474205");
createMarker(map_canvas, markerPos16, "いいの歯科医院村上市飯野2-5-6
TEL 0254-52-5756
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.221479", "139.474205"));
cnt = cnt+1;
var markerPos17 = new google.maps.LatLng("38.225754", "139.484337");
createMarker(map_canvas, markerPos17, "新町歯科医院村上市新町2-46
TEL 0254-52-1182
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.225754", "139.484337"));
cnt = cnt+1;
var markerPos18 = new google.maps.LatLng("38.269346", "139.537598");
createMarker(map_canvas, markerPos18, "あさひ歯科医院村上市岩沢5564-1
TEL 0254-72-1313
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.269346", "139.537598"));
cnt = cnt+1;
var markerPos19 = new google.maps.LatLng("38.220829", "139.465217");
createMarker(map_canvas, markerPos19, "丹田矯正歯科村上市田端町10-8清水屋ビル2F
TEL 0254-50-1515
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.220829", "139.465217"));
cnt = cnt+1;
var markerPos20 = new google.maps.LatLng("38.12381", "139.442413");
createMarker(map_canvas, markerPos20, "加藤歯科クリニック村上市山口字野中468-1番地
TEL 0254-50-5115
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.12381", "139.442413"));
cnt = cnt+1;
var markerPos21 = new google.maps.LatLng("38.219196", "139.465134");
createMarker(map_canvas, markerPos21, "さとう歯科クリニック村上市田端町8-10
TEL 0254-53-8330
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.219196", "139.465134"));
cnt = cnt+1;
var markerPos22 = new google.maps.LatLng("38.192538", "139.438066");
createMarker(map_canvas, markerPos22, "いわふね歯科クリニック村上市岩船上町1-16
TEL 0254-56-7744
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.192538", "139.438066"));
cnt = cnt+1;
var markerPos23 = new google.maps.LatLng("38.2228824", "139.4917781");
createMarker(map_canvas, markerPos23, "まきの歯科医院村上市新町15-15
TEL 0254-52-2880
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.2228824", "139.4917781"));
cnt = cnt+1;
var markerPos24 = new google.maps.LatLng("38.1589609", "139.42917");
createMarker(map_canvas, markerPos24, "さくらい歯科クリニック村上市北新保571-55
TEL 0254-60-1230
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.1589609", "139.42917"));
cnt = cnt+1;
var markerPos25 = new google.maps.LatLng("38.2240988", "139.4898449");
createMarker(map_canvas, markerPos25, "お城山歯科クリニック村上市新町9-86
TEL 0254-52-1111
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.2240988", "139.4898449"));
cnt = cnt+1;
var markerPos26 = new google.maps.LatLng("38.2232064", "139.4641309");
createMarker(map_canvas, markerPos26, "肴町病院村上市田端町16-7
TEL 0254-53-2781
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.2232064", "139.4641309"));
cnt = cnt+1;
var markerPos27 = new google.maps.LatLng("38.2206458", "139.4665086");
createMarker(map_canvas, markerPos27, "新潟県厚生連村上総合病院村上市田端町2-17
TEL 0254-52-4362
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.2206458", "139.4665086"));
cnt = cnt+1;
var markerPos28 = new google.maps.LatLng("38.285949", "139.526376");
createMarker(map_canvas, markerPos28, "佐藤医院村上市猿沢2221
TEL 0254-60-2221
[医院詳細]
 ");
bounds.extend(new google.maps.LatLng("38.285949", "139.526376"));
    if (cnt > 0) {
        if (cnt == 1) {
            map_canvas.setCenter(new google.maps.LatLng(38.285949, 139.526376));
            map_canvas.setZoom(15);
        } else {
            map_canvas.fitBounds(bounds);
        }
        if(document.getElementById("search_cnt") != null) {
            document.getElementById("search_cnt").innerHTML = cnt + "件該当しました。";
        }
    } else {
        if(document.getElementById("search_cnt") != null) {
            document.getElementById("search_cnt").innerHTML = "該当する情報がありません。";
        }
    }
}
function createMarker(map, latlng, text) {
	var infoWndOpts = {
		content : text
	};
	var infoWnd = new google.maps.InfoWindow(infoWndOpts);
	var markerOpts = {
		position : latlng,
		map : map
	};
	var marker = new google.maps.Marker(markerOpts);
	google.maps.event.addListener(marker, "click", function(){
		//先に開いた情報ウィンドウがあれば、closeする
		if (currentInfoWindow) {
			currentInfoWindow.close();
		}
		//情報ウィンドウを開く
		infoWnd.open(map, marker);
		currentInfoWindow = infoWnd;
	});
	return marker;
}
function getLatLng(address) {
	if (geocoder) {
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				var bounds = new google.maps.LatLngBounds();
				for (var i in results) {
					if (results[i].geometry) {
						// 緯度経度を取得
						latlng = results[i].geometry.location;
						// 緯度
						map_Point_Y = latlng.lat();
						// 経度
						map_Point_X = latlng.lng();
						map_canvas.setCenter(latlng);
					}
				}
				setMarker();
			}
		});
	}
}
window.onload = initialize;