//
	function cal_length(x1,y1, x2,y2){
		var x;
		var y;
		var L;
		var A;
		// var c;
		x1 = x1 * Math.PI / 180.0;
		y1 = y1 * Math.PI / 180.0;
		x2 = x2 * Math.PI / 180.0;
		y2 = y2 * Math.PI / 180.0;
		A = 6378137; // 地球の赤道半径(m単位)
		x = A * (x2-x1) * Math.cos( y1 );
		y = A * (y2-y1);
		L = Math.sqrt(x*x + y*y);	// メートル単位の距離
		//c = Math.atan(y / x) *180.0/ Math.PI;	// 方角　東：0(0度)，北：1/2π(90度)，西：π(180度)，南：3/2π(270度)
		return  L;
	}

	function all_clear(){
		vpoints=[];
		do_back_bn();
	}

	function do_back_bn(){
		if(vpoints.length != 0) {
			vpoints.pop();
		}
		if(vpoints.length == 0) {
			if(startPointer != null)
				map.removeOverlay(startPointer);
		} else {
	//		zoom_lv = map.getZoom();
	//		p = new GLatLng(vpoints[vpoints.length-1].y, vpoints[vpoints.length-1].x);
	//		map.setCenter(p, zoom_lv);
		}
		// 最初の1つで，マーカーがない場合は，マーカー復活
		if(vpoints.length == 1 && startPointer == null) {
			add_start_marker(vpoints[0].x,vpoints[0].y);
		}
		update_line();
		udate_now_pos();
	}

	function move_to(x1,y1) {
	//	zoom_lv = map.getZoom();
		var p = new GLatLng(y1, x1);
	//	map.setCenter(p, zoom_lv);
		map.panTo(p);
		delete p;
	}

	function update_line(){
		if(last_line != null) {
			map.removeOverlay(last_line);
			delete last_line;
		}
		last_line = new GPolyline(vpoints,'#ff0000');
		map.addOverlay(last_line);

		len = 0;
		for(i = 0; i < vpoints.length-1; i++) {
			len += cal_length(vpoints[i].x,vpoints[i].y, vpoints[i+1].x,vpoints[i+1].y);
		}
		document.data.len.value = len/1000;
	}

	// スタート地点のマーカーを作成
	function add_start_marker(x,y){
		startPos = new GLatLng(y, x);
		startPointer = new GMarker(startPos,startIcon);

		GEvent.addListener(startPointer, 'click', function(overlay, point){
				// マウスをクリックしたときの処理。
					if(startPointer != null) {
						map.removeOverlay(startPointer);
						delete startPointer;
						delete startPosr;
						startPointer = null;
						startPos = null;

						// 最後の１つだけだったら，座標も消去
						//if(vpoints.length==1) {
						//	vpoints.pop();
						//}
					}
				});
		map.addOverlay(startPointer);

	}

	// 現在位置を最後の位置
	function udate_now_pos(){
		if(vpoints.length>=1) {
			document.data.k.value = vpoints[vpoints.length-1].x;
			document.data.i.value = vpoints[vpoints.length-1].y;
		}
	}

	function clz_do_all(){
		var len;
		var i;
		var now_pos_disp_v = document.getElementById("now_pos_disp");
		if(clz_pos >= vpoints.length) {
			now_work = 0;
			now_pos_disp_v.innerHTML = " 終了 :" +now_pos_disp_v.innerHTML;
			clz_pos = 0;
		} else {
			move_to(vpoints[clz_pos].x, vpoints[clz_pos].y);
			document.data.k.value = vpoints[clz_pos].x;
			document.data.i.value = vpoints[clz_pos].y;
			len = 0;
			for(i = 0; i < clz_pos; i++) {
				len += cal_length(vpoints[i].x,vpoints[i].y, vpoints[i+1].x,vpoints[i+1].y);
			}
			//document.data.p_len.value = len/1000;
			now_pos_disp_v.innerHTML = " "+(len/1000);
			clz_pos++;
			inval = setTimeout("clz_do_all()", 1000);
		}
	}

	function clz_all(){
		if(now_work == 0) {
			now_work = 1;
			if(clz_pos >= vpoints.length) {
				clz_pos = 0;
			}
			clz_do_all();
		} else {
			clearInterval(inval);
			now_work = 0;
		}
	}

