rm *.png *.jpg *.txt log 2>/dev/null

zoom=$3
mapsize=$4

x=`java  -classpath . GoogleTile $1 $2 $zoom|grep x=|cut -d '=' -f2`
y=`java  -classpath . GoogleTile $1 $2 $zoom|grep y=|cut -d '=' -f2`
URL="www.toeat.com/Map/JS/"

ms_original=$mapsize
let xs=x/mapsize*mapsize
let ys=y/mapsize*mapsize
echo $xs $ys $zoom $mapsize


yc=0
	let zm=ms_original/mapsize
	echo "ms_original:$ms_original:$mapsize:$zm"
while  [ $yc -lt $mapsize ]
do
	xc=0
	let y=ys+yc
	while  [ $xc -lt $mapsize ]
	do
		let x=xs+xc
		let y=ys+yc
		blX=`java  -classpath . GoogleTileUtils $x $y $zoom|grep cornerX|cut -d '=' -f2`
		blY=`java  -classpath . GoogleTileUtils $x $y $zoom|grep cornerY|cut -d '=' -f2`

		let x=x+1
		let y=y-1
		trX=`java  -classpath . GoogleTileUtils $x $y $zoom|grep cornerX|cut -d '=' -f2`
		trY=`java  -classpath . GoogleTileUtils $x $y $zoom|grep cornerY|cut -d '=' -f2`
		#echo "$blY,${blX}x$trY,$trX"
wget -t0 -o log -O - "${URL}$blY,${blX}x$trY,${trX}@0" | tr -d '\r\n' |sed -e 's/addMarker/\n/g' |grep "( \"restaurant"|cut -d '"' -f4,7,24|sed -e 's/"//g'|sed -e 's/ true );    sortedList.push(//g' >> _restaurants$$.tmp


		let xc=xc+1
	done
		let yc=yc+1
done
sort -u _restaurants$$.tmp | {
read a
while [ -n "$a" ]
do
         echo "`echo $a|cut -d , -f2,3`,`echo $a|cut -d , -f1,4`"
        read a
done
}| sort -t "," -k 1,2|sed -e "s/&#039;/'/g"|sed -e "s/&amp;/\&/g" >__restaurants.txt
rm _restaurants$$.tmp 2>/dev/null

