<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>code.nosvamosdetapas.com</title>
	<link>http://code.nosvamosdetapas.com</link>
	<description>code just before eating!</description>
	<pubDate>Mon, 07 Jan 2008 00:29:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>How far from my way?</title>
		<link>http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/</link>
		<comments>http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 10:17:15 +0000</pubDate>
		<dc:creator>palako</dc:creator>
		
		<category><![CDATA[geometry]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[maps]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/</guid>
		<description><![CDATA[Wife, children, pet, luggage, GPS, water, air pressure, oil levels, &#8230;&#8230;. everything is packed and ready for your deserved holidays, and there you go for your trip to Paris. Of course, you wan&#8217;t to be there as soon as possible, but you will have to stop to eat, at least two times a day, and [...]]]></description>
			<content:encoded><![CDATA[<p>Wife, children, pet, luggage, GPS, water, air pressure, oil levels, &#8230;&#8230;. everything is packed and ready for your deserved holidays, and there you go for your trip to Paris. Of course, you wan&#8217;t to be there as soon as possible, but you will have to stop to eat, at least two times a day, and you have this bunch of places you&#8217;ve been told to be worth stopping because of the great food they serve. Oh yes, they&#8217;re good, but you won&#8217;t go 30 miles away from your route just to eat. If  only you could know how far from your straight way those places are &#8230;</p>
<p align="center"><img src="http://code.nosvamosdetapas.com/wp-content/uploads/2008/01/20km.png" alt="20km" />                                               <img src="http://code.nosvamosdetapas.com/wp-content/uploads/2008/01/50km.png" alt="50km" /></p>
<h2>The problem</h2>
<p>Draw a polygon that surrounds a (poly)line in such a way than the outer line that forms the polygon is a given distance from the former line.</p>
<h2>First things first</h2>
<p>I will use the same structure for the code and examples we&#8217;ve been using in older posts, so you&#8217;ll be quite confortable if you&#8217;ve been following us (if not, you should, they are worth reading).</p>
<p>A brief abstract for new readers. Every piece of code here is javascript, we use the GoogleMaps API and very basic stuff from prototype (you don&#8217;t need to know anything about prototype to understand this) we have a GMap2 object, an array of points (of interest),  <a href="http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/" title="The boundingbox problem" target="_blank">an extension on the GPolygon object to determine if a Gpoint is contained in a polygon</a>, and a piece of code we run on body load to put everything together and to add the listeners we are  using.</p>
<h2>Drawing the line</h2>
<p>This is not what the post is about, so very quickly, take a look at the code and you&#8217;ll understand it:</p>
<pre class="prettyprint">function addListeners(map){

//... other listeners...
GEvent.addListener(map, "click", onClick);
}</pre>
<pre class="prettyprint">var points = $A(); //Points array to draw the polyline
var lineOverlay =null;   //The polyline

function onClick(overlay,point) {

 points.push(point);
 if(lineOverlay!=null)
 	map.removeOverlay(lineOverlay);
 if(points.length>1){
 	lineOverlay = new GPolyline(points,"#0000ff",2);
 	map.addOverlay(lineOverlay);
 }
}</pre>
<h2>Here comes the math</h2>
<p>To draw a GPolygon I&#8217;m first gathering all the points in an array and then passing the array to the GPolygon constructor.</p>
<p>For each point of the former polyline, two points for the polygon will arise. Imagine that our line is quite vertical. Then some points will be situated on its right and some on its left. But this pair of points for each point from the polyline are not contiguous in the polygon, but simetrically situated on the array. Let&#8217;s say I have a line made up of four points, A, B, C and D, in that order. I will have two points from every of those, let name them A<sub>1</sub>, A<sub>2</sub>, B<sub>1</sub>, B<sub>2</sub>, C<sub>1</sub>, C<sub>2</sub>, D<sub>1</sub> and D<sub>2</sub>. If I start drawing the polygon from the point A, this will be the layout of the polygon points in the array: [A<sub>1</sub>, B<sub>1</sub>, C<sub>1</sub>, D<sub>1</sub>, D<sub>2</sub>, C<sub>2</sub>, B<sub>2</sub>,A<sub>2</sub>].</p>
<p>Ok, now, how to figure out the polygon points? A little math will do the work. Let&#8217;s take the first two points, A, and B, to go for points A<sub>1</sub> and A<sub>2</sub>.</p>
<p>I want to figure out the position of two points at each side of the first point situated over the rect that goes through this point (A) and which incline is perpendicular to the segment that joins the point with the next point in the polyline (B).</p>
<p>I know points A and B coordinates, (A<sub>x</sub>, A<sub>y</sub>) and (B<sub>x</sub>, B<sub>y</sub>), therefore I can find the incline of the rect that goes through them both with the formula:</p>
<p align="center">m<sub>1</sub>= A<sub>y</sub> - B<sub>y</sub> / A<sub>x</sub> - B<sub>x</sub></p>
<p align="left">and the incline of the perpendicular rect:</p>
<p align="center">m<sub>2</sub>= -1 / m<sub>1</sub></p>
<p align="left">Coordinates of  two points separated a given distance (d) over the rect that goes through point A with this last incline is a matter of trigonometry:</p>
<p align="center">α = atan(m<sub>2</sub>)</p>
<p align="center">A<sub>1<sub>x</sub></sub> = A<sub>x</sub> - d*cos(α)                                                                                                                                                                  A<sub>1<sub>y</sub></sub> = A<sub>y</sub> - d*sin(α)</p>
<p align="center">A<sub>2<sub>x</sub></sub> = d*cos(α) + A<sub>x</sub>                                                               A<sub>2<sub>Y</sub></sub> = d*sin(α) + A<sub>y</sub></p>
<p align="left">As this A point is the first in the iteration, we will add A1 and A2 to the polygon points arrat straight away. Remember,  A<sub>1</sub> as the first element and A<sub>2</sub> as the last one.</p>
<p align="center"><img src="http://code.nosvamosdetapas.com/wp-content/uploads/2008/01/paralels.png" alt="paralels" /></p>
<p align="left">And the rects that go through this points paralels to the AB segment are:</p>
<p align="center">r<sub>1</sub>: y = m<sub>1</sub> (x-A<sub>1<sub>x</sub></sub>) + A<sub>1<sub>y</sub></sub></p>
<p align="center">r<sub>2</sub>: y = m<sub>1</sub> (x-A<sub>2<sub>x</sub></sub>) + A<sub>2<sub>y</sub></sub></p>
<p>Time to iterate. Once you are here, repeat the operations for segment BC, that is, calculate BC incline, its perpendicular, look for two points over that perpendicular, B<sub>1</sub> and B<sub>2</sub>, situated a distance &#8220;d&#8221; away from B, and finally calculate the ecuations of the paralel rects to BC that go through those two points.</p>
<p align="center">r<sub>3</sub>: y = m<sub>3</sub> (x-B&#8217;<sub>1<sub>x</sub></sub>) + B&#8217;<sub>1<sub>y</sub></sub></p>
<p align="center">r<sub>4</sub>: y = m<sub>3</sub> (x-B&#8217;<sub>2<sub>x</sub></sub>) + B&#8217;<sub>2<sub>y</sub></sub></p>
<p>Be careful here! Those B&#8217;<sub>1</sub> and B&#8217;<sub>2</sub> points are not to be added to the gpolygon.  The points we are looking for are  what we get intersecting those rects with the ones from the previous iteration. This is about solving a system with two ecuations and two variables, isolating one of the variables and them using its value on one ecuation to calculate the other.</p>
<p align="center"> <img src="http://code.nosvamosdetapas.com/wp-content/uploads/2008/01/intersection.png" alt="Intersection" /></p>
<p align="center">B<sub>1<sub>x</sub></sub> = (-m<sub>3</sub>*B&#8217;<sub>1<sub>x</sub></sub>+B&#8217;<sub>1<sub>y</sub></sub>+m<sub>1</sub>*A<sub>1<sub>x</sub></sub>-A<sub>1<sub>y</sub></sub>)/(m<sub>1</sub>-m<sub>3</sub>)                          B<sub>1<sub>y</sub></sub>=m<sub>3</sub>*(B<sub>1<sub>x</sub></sub>-B&#8217;<sub>1<sub>x</sub></sub>)+B&#8217;<sub>1<sub>y</sub></sub></p>
<p align="center"> B<sub>2<sub>x</sub></sub>=(-m<sub>3</sub>*B&#8217;<sub>2<sub>x</sub></sub>+B&#8217;<sub>2<sub>y</sub></sub>+m<sub>1</sub>*A<sub>2<sub>x</sub></sub>-A<sub>2<sub>y</sub></sub>)/(m<sub>1</sub>-m<sub>3</sub>)                                                                                                           B<sub>2<sub>y</sub></sub>=m<sub>3</sub>*(B<sub>2<sub>x</sub></sub>-B&#8217;<sub>2<sub>x</sub></sub>)+B&#8217;<sub>2<sub>y</sub></sub></p>
<p>There you go, two more points to add. Remember that each of them go to one end on the array (for the B point, B1 would go to array[1] and B2 to array[array.length-2] (Do I need to say that javascript arrays are zero based? No I don&#8217;t&#8230;).</p>
<p>The hard work is already done, as this iterations will take you to the last point. For this last ones (D in our four points line example), you only need two points over the perpendicular, just as you did for the fisrt two. You already have the calculations for the incline of the perpendicular from last iteration, so you can straightly get the last pair of points (D1 and D2), which you will add to the array in the middle positions (this two will be contiguous).</p>
<p>If you get here and you understood everything, you won&#8217;t have any problem with the code, which is commented and is quite similar to what you&#8217;ve already read.</p>
<h2>There&#8217;s always something tricky</h2>
<p>When I first coded this, I spent several hours trying to figure out why I wasn&#8217;t working properly. The problem was that, sometimes, the lines of the polygon crossed their way of the line, and the &#8220;sometimes&#8221; happened to be when in a group of three points, they point in the middle was above of below the other two. Quite weird. Making some changes, What I obtained was that when in a group of three, if the point in the middle was the most left or right one, the lines crossed.</p>
<p>So, what did I do? Easy and miserable. I blame google for it and added a boolean &#8220;swapped&#8221; variable that I use to return the points  where they should be before adding them to the array. You will clearly find and understand that also in the code.</p>
<h2>What did I left behind</h2>
<p>As the code is intended to be educational, there are some checks I didn&#8217;t do to keep it clear. I.e. keep in mind that horizontal segments will result in a division by zero when calculating the incline. Once you get that, mind it again to calculate the perpendicular. Same precautions must be taken when solving the ecuations system, as two consecutive segments with the same incline will result also in a division by zero error.</p>
<p>This aproach solves quite well the problem, but there are circunstances where you will find not the expected behaviours. That will happen, i.e. when you have segments in your line that are shorter than the distance you want the polygon to be drawn away.</p>
<p><a href="http://code.nosvamosdetapas.com/googlemaps/surrounding/surrounding.html" title="Surrounding polygons">Test it</a>, <a href="http://code.nosvamosdetapas.com/googlemaps/surrounding.zip" title="Surrounding lines with polygons" target="_blank">download it</a>, and leave me your comments.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;title=How+far+from+my+way%3F" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;title=How+far+from+my+way%3F" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;title=How+far+from+my+way%3F" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;title=How+far+from+my+way%3F&amp;description=How+far+from+my+way%3F" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;bm_description=How+far+from+my+way%3F" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;title=How+far+from+my+way%3F" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;title=How+far+from+my+way%3F" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/&amp;t=How+far+from+my+way%3F" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2008/01/05/how-far-from-my-way/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Changing the radius of the circle</title>
		<link>http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/</link>
		<comments>http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/#comments</comments>
		<pubDate>Tue, 25 Dec 2007 21:52:11 +0000</pubDate>
		<dc:creator>kan</dc:creator>
		
		<category><![CDATA[google]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[maps]]></category>

		<category><![CDATA[nosvamosdetapas.com]]></category>

		<category><![CDATA[google maps javascript drag drop]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/</guid>
		<description><![CDATA[Some days ago, Palako wrote an interesting post about drawing polygons with your mouse so we&#8217;re able to change the size of our &#8220;typical&#8221; circle. I&#8217;ve developed another way to do this: the circle has an icon which can modify its radius using the drag&#8217;n'drop feature of the GMarker.

When the circle is drawn, we put a marker [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago, Palako <a href="http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/">wrote</a> an interesting post about drawing polygons with your mouse so we&#8217;re able to change the size of our &#8220;typical&#8221; circle. I&#8217;ve developed another way to do this: the circle has an icon which can modify its radius using the drag&#8217;n'drop feature of the <a href="http://code.google.com/apis/maps/documentation/reference.html#GMarker">GMarker</a>.</p>
<p><center><img src="http://code.nosvamosdetapas.com/wp-content/uploads/2007/12/example-radius.png" alt="Example Radius" /></center></p>
<p>When the circle is drawn, we put a marker on the circumference setting listeners for drag and drop events. But, we have the first problem because we have the central point of the circle, defined by its <em>longitude and latitude</em>, and the radius in <em>kilometers</em>. So, we need to know a point of the circumference in longitude and latitude:</p>
<pre class="prettyprint">
var p1 = new GLatLng(actualPoint.lat()+0.1, actualPoint.lng());
var p2 = new GLatLng(actualPoint.lat(), actualPoint.lng()+0.1);
var latConv = actualPoint.distanceFrom(p1)/100;
var lngConv = actualPoint.distanceFrom(p2)/100;
var pint = new GLatLng(actualPoint.lat() + (newRadius/latConv *
  Math.cos(0 * Math.PI/180)), actualPoint.lng() + 
  (newRadius/lngConv * Math.sin(0 * Math.PI/180)));
</pre>
<p>So, we put the marker in that point adding the <strong>dragstart</strong> (for drag events) and the <strong>dragend</strong> (for drop events) listeners and they set a flag if the user is dragging the marker.</p>
<pre class="prettyprint">
var markerOptions = { draggable: true };

marker=new GMarker(pint,markerOptions);
GEvent.addListener(marker, "dragstart", function() {
	document.getElementById("dragstart").innerHTML = "Drag start Coords: "
   + marker.getPoint().lat() + ", "+marker.getPoint().lng();
	drag=true;
});
GEvent.addListener(marker, "dragend", function() {
	checkDraggedMark();
	drag=false;
});
map.addOverlay(marker);
</pre>
<p>If the dragend listener is called or this flag is active and moving the marker (dragging the marker) the circle and contained PoIs are updated:</p>
<pre class="prettyprint">
if (drag==true) {
  var newRadius=(actualPoint.distanceFrom(marker.getPoint())/1000);
  document.getElementById("dragend").innerHTML = "Radius: "+newRadius+" km";
  if (overlay)
   map.removeOverlay(overlay);
  overlay = drawCircle(actualPoint, newRadius, 30);
  showSelectedPois();
}
</pre>
<p>Of course, you can <a href="/googlemaps/test5.html">try</a> this example or <a href="/googlemaps/test5.zip">download</a> the code!</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;title=Changing+the+radius+of+the+circle" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;title=Changing+the+radius+of+the+circle" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;title=Changing+the+radius+of+the+circle" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;title=Changing+the+radius+of+the+circle&amp;description=Changing+the+radius+of+the+circle" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;bm_description=Changing+the+radius+of+the+circle" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;title=Changing+the+radius+of+the+circle" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;title=Changing+the+radius+of+the+circle" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/&amp;t=Changing+the+radius+of+the+circle" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2007/12/25/changing-the-radius-of-the-circle/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Maps and Picasa</title>
		<link>http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/</link>
		<comments>http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 17:52:57 +0000</pubDate>
		<dc:creator>arcturus</dc:creator>
		
		<category><![CDATA[json]]></category>

		<category><![CDATA[maps]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[picasa]]></category>

		<category><![CDATA[integration]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[picassa]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2007/12/11/maps-and-picasa/</guid>
		<description><![CDATA[The Google pic service, Picasa, offers us the possibilty to add geoinformation in a easy way.But it’s not so easy to retrieve the pics from a specific location.Endeed we are going to use an undocumented feature from Picasa API.
We asked Google guys to add a new feature, pics search by geoinformation, for GData Picasa API, [...]]]></description>
			<content:encoded><![CDATA[<p>The Google pic service, <a href="http://picasaweb.google.com" title="great_service" target="_blank">Picasa</a>, offers us the possibilty to add geoinformation in a easy way.But it’s not so easy to retrieve the pics from a specific location.Endeed we are going to use an undocumented feature from Picasa API.</p>
<p>We asked Google guys to add a new feature, pics search by geoinformation, for GData Picasa API, and the redirected us to a post where explain how to do this:You have to add an extra param to the query pics inside the desired boundingbox:</p>
<p>http://picasaweb.google.com/data/feed/base/all?bbox= west,south,east,north</p>
<p>for example:</p>
<p><a href="http://picasaweb.google.com/data/feed/base/all?bbox=-5.998,37.367,-5.953,37.403" title="test_it" target="_blank">http://picasaweb.google.com/data/feed/base/all?bbox=-5.998,37.367,-5.953,37.403</a></p>
<p>But this query give us all the pics in this area, still we can’t use the bbox param in pic user searchs. What we can do if wanna get only our pics? We have a weird trick, in the name of the pics we have added a mark, and we use gdata query param to search for this mark, so our request looks like:</p>
<p>http://picasaweb.google.com/data/feed/base/all?bbox=west,south,east,north&amp;q=mark_string</p>
<p>for example:</p>
<p><a href="http://picasaweb.google.com/data/feed/base/all?bbox=-5.998,37.367,-5.953,37.403&amp;q=nosvamosdetapas" title="test_it" target="_blank"> http://picasaweb.google.com/data/feed/base/all?bbox=-5.998,37.367,-5.953,37.403&amp;q=nosvamosdetapas</a></p>
<p>Add two more params to complete the petition:</p>
<blockquote>
<ol>
<li>max-results=100 : Limit the number of returned pics to 100.</li>
<li>alt=json: Get the response in json format.</li>
</ol>
</blockquote>
<p>We encapsulate the call in a php file, and get the results using curl like this:</p>
<pre class="prettyprint">$curl_handle=curl_init();
$url ="http://picasaweb.google.com/data/feed/base/all?bbox=".$_GET["bounds"];
$url.="&amp;q=nosvamosdetapas.com&amp;maxresults=100&amp;alt=json";
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);curl_close($curl_handle);
print $buffer;</pre>
<p>The reason why we use a php script to retrieve the info is cause we can´t make a xhttprequest to an external server, so we make this xhttprequest to a script in the local domain.</p>
<p>We get a list of pics, in this pics we get the geodata information encoded, but most of the pics should have been taken from the same point, so our first task is extract geodata information and see how many different points we have pics for.We do this with tree javascript classes, ussing prototype 1.6:</p>
<pre class="prettyprint">var PicasaPic = Class.create({
initialize: function(jsonObj)
{
this.author = jsonObj.author.name;
this.title = jsonObj.title.$t;
this.thumb = jsonObj.media$group.media$thumbnail[0].url;
this.url = jsonObj.link[1].href
}
,
getAuthor: function(){ return this.author; }
,
getTitle: function() { return this.title; }
,
getThumb: function() { return this.thumb; }
,
getURL: function() { return this.url; }
});</pre>
<p>This class will store all the data we need to know from a picture.</p>
<p>And this one, will represent a point of interest, poi, with an array of pics associated:</p>
<pre class="prettyprint">var PicPoi = Class.create({
initialize: function(point)
{
this.gpoint = point;
this.pics = $A();
}
,
getPoint: function(){ return this.gpoint; }
,
addPic: function(pic){ this.pics.push(pic); }
,
getPics: function(){ return this.pics; }
});</pre>
<p>Our last class, the poi manager, a class that will check all the json entries and add pics to existing points or will create the points:</p>
<pre class="prettyprint">var PicPoiManager = Class.create({	initialize: function(){

 	this.picpois = $A();

 }

 ,

 analizePic: function(jsonObj, polygon){

 	var posArray = jsonObj.georss$where.gml$Point.gml$pos.$t.split(" ");

 	var point = new GLatLng(posArray[0],posArray[1]);

//Check again against the polygon bounding box

 	if(!polygon.contains(point))

 		return;

var found = false;

 	for(j=0;j
<this.picpois.length>if (point.equals(this.picpois[j].getPoint())){

 			found = true;

 			this.picpois[j].addPic(new PicasaPic(jsonObj));

 		}

 	}</this.picpois.length>if(!found){

 		var picpoi = new PicPoi(point);

 		picpoi.addPic(new PicasaPic(jsonObj));

 		this.picpois.push(picpoi);

 	}

}

 ,

 getPois: function(){	return this.picpois; }

 ,

 clear: function() { this.picpois = $A(); }

});</pre>
<p>You can test the results <a href="http://code.nosvamosdetapas.com/googlemaps/test4.html" title="test_whole_example" target="_blank">here</a> or download the source code from this <a href="http://code.nosvamosdetapas.com/googlemaps/test4.tar.gz" title="download_it">link</a>.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;title=Maps+and+Picasa" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;title=Maps+and+Picasa" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;title=Maps+and+Picasa" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;title=Maps+and+Picasa&amp;description=Maps+and+Picasa" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;bm_description=Maps+and+Picasa" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;title=Maps+and+Picasa" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;title=Maps+and+Picasa" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/&amp;t=Maps+and+Picasa" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2007/12/06/maps-and-picasa/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drawing polygons with your mouse</title>
		<link>http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/</link>
		<comments>http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 21:37:03 +0000</pubDate>
		<dc:creator>palako</dc:creator>
		
		<category><![CDATA[google]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[maps]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/</guid>
		<description><![CDATA[A slight modification to The bounding box problem will let us draw polygons (i.e. circles) centered anywhere on the map with arbitrary radius based on mouse actions. As the circle is drawn, points of interest within its area will be shown.
 
The dragging functionality is reserved to move the map, so we will start the [...]]]></description>
			<content:encoded><![CDATA[<p>A slight modification to <a href="http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/" title="The bounding box problem" target="_blank">The bounding box problem</a> will let us draw polygons (<a href="http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/" title="Drawing circles on google maps" target="_blank">i.e. circles</a>) centered anywhere on the map with arbitrary radius based on mouse actions. As the circle is drawn, points of interest within its area will be shown.</p>
<p align="center"> <img src="http://code.nosvamosdetapas.com/wp-content/uploads/2007/11/drawingpolygons.png" alt="Drawing polygons caption" align="middle" height="264" width="268" /></p>
<p>The dragging functionality is reserved to move the map, so we will start the drawing with a click and will finish it with another click. To let the user know that a drawing is being taken place, we will change the cursor.</p>
<p>For the sake of WYSIWYG, the polygon will be shown in real time as you move your mouse. A tiny line will show the radius conecting the center of the polygon with your mouse pointer.</p>
<p>So, first things first, capture the onclick event:</p>
<pre class="prettyprint">     GEvent.addListener(map, "click", onClick);</pre>
<p>When the user clicks the map a new polygon drawing starts or ends. We are storing in a global variable the center of the polygon, so it can also be used to set the state. A null center means the drawing has not started, whereas a not null means you are actually drawing. That means:</p>
<p>If the drawing is starting (center was null):</p>
<ol>
<li>Clear any previous polygon or marker.</li>
<li>Set the center of the polygon.</li>
<li>Change the cursor to indicate the drawing state.</li>
</ol>
<p>If the drawing is ending (center was set):</p>
<ol>
<li>Unset the center.</li>
<li>Remove the Tiny line conecting the center with the edge.</li>
</ol>
<pre class="prettyprint">function onClick(overlay,point) {
	if(myCenter==null) {
		myCenter=point;
		document.getElementById("map").firstChild.firstChild.style.cursor ="crosshair";
		map.clearOverlays();
	}
	else {
		myCenter=null;
		map.removeOverlay(lineOverlay);
	}
}</pre>
<p>After a start drawing click, we want to see the polygon being drawn as we move the mouse, so we have to modify our mousemove callback:</p>
<ol>
<li>If a polygon (and its radius line) has been drawn before, remove it.</li>
<li>Draw the new polygon and its radius tiny line.</li>
<li>Draw points within the area of the polygon.</li>
</ol>
<pre class="prettyprint"> 	if(myCenter!=null) {
		if(overlay!=null)
			map.removeOverlay(overlay);
		if(lineOverlay!=null)
			map.removeOverlay(lineOverlay);
		var myRadius = myCenter.distanceFrom(point);
		overlay = drawCircle(myCenter, myRadius/1000,30);
		lineOverlay = new GPolyline(new Array(myCenter,point),"#0000ff",1);
		map.addOverlay(lineOverlay);
		showSelectedPois();
	}</pre>
<p>One extra line in showSelectedPois() to hide the markers when they are not contained within the area of the polygon, and we are done.</p>
<pre class="prettyprint">		if (overlay.contains(item))
    			map.addOverlay(pois[i]);
    		else
   			pois[i].hide();</pre>
<p>Feel free to <a href="http://code.nosvamosdetapas.com/googlemaps/drawingPolygons.html" target="_blank" title="Drawing polygons example">test it</a> or <a href="http://code.nosvamosdetapas.com/googlemaps/drawingPolygons.zip" title="Drawing polygons code" target="_blank">download it</a>.</p>
<p>In future posts, we might resize the polygon once created and  move the map as you aproach the edges.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;title=Drawing+polygons+with+your+mouse" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;title=Drawing+polygons+with+your+mouse" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;title=Drawing+polygons+with+your+mouse" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;title=Drawing+polygons+with+your+mouse&amp;description=Drawing+polygons+with+your+mouse" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;bm_description=Drawing+polygons+with+your+mouse" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;title=Drawing+polygons+with+your+mouse" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;title=Drawing+polygons+with+your+mouse" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/&amp;t=Drawing+polygons+with+your+mouse" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2007/11/27/drawing-polygons-with-your-mouse/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Playing with the size of markers</title>
		<link>http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/</link>
		<comments>http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/#comments</comments>
		<pubDate>Sun, 25 Nov 2007 21:48:04 +0000</pubDate>
		<dc:creator>kan</dc:creator>
		
		<category><![CDATA[google]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[maps]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/</guid>
		<description><![CDATA[I don&#8217;t like when a map is filled with markers covering all streets there. As there is no way to use vectorial icons for markers, I though I could write a sample which tries to emulate them.
So, we have the same icon in different sizes:

: 8 pixels of width
: 12 pixels of width
: 16 pixels [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t like when a map is filled with markers covering all streets there. As there is no way to use vectorial icons for markers, I though I could write a sample which tries to emulate them.</p>
<p>So, we have the same icon in different sizes:</p>
<ul>
<li><img src="http://code.nosvamosdetapas.com/googlemaps/img/mark8.png" alt="8" />: 8 pixels of width</li>
<li><img src="http://code.nosvamosdetapas.com/googlemaps/img/mark12.png" alt="12" />: 12 pixels of width</li>
<li><img src="http://code.nosvamosdetapas.com/googlemaps/img/mark16.png" alt="16" />: 16 pixels of width</li>
</ul>
<p>Now, we only need to choose which icon we want depending on the zoom level. So, we&#8217;re going to add a callback function for zoom events:</p>
<pre class="prettyprint">
GEvent.addListener(map, "zoomend", zoomCallback);

function zoomCallback() {
	document.getElementById("zoom").innerHTML = "Zoom: " + map.getZoom();
	initPoIs();
	showSelectedPois();
}</pre>
<p>The <strong>initPoIs()</strong> method checks if some markers have been created previously, and then it updates them using the appropiate icon:</p>
<pre class="prettyprint">
function initPoIs() {
  var blueIcon = new GIcon(G_DEFAULT_ICON);
  if (map.getZoom()>=16) {
    blueIcon.image = "http://.../mark16.png";
    blueIcon.iconSize = new GSize(16, 16);
    blueIcon.shadowSize = new GSize(30, 16);
    blueIcon.iconAnchor = new GPoint(3, 16);
    blueIcon.infoWindowAnchor = new GPoint(7, 2);
    blueIcon.infoShadowAnchor = new GPoint(14, 14);
  }
  else if (map.getZoom()>=14&amp;&amp;map.getZoom()<=15) {
    blueIcon.image = "http://.../mark12.png";
    blueIcon.iconSize = new GSize(12, 12);
    blueIcon.shadowSize = new GSize(20, 12);
    blueIcon.iconAnchor = new GPoint(5, 12);
    blueIcon.infoWindowAnchor = new GPoint(5, 2);
    blueIcon.infoShadowAnchor = new GPoint(10, 10);
  }
  else {
    blueIcon.image = "http://.../mark8.png";
    blueIcon.iconSize = new GSize(8, 8);
    blueIcon.shadowSize = new GSize(14, 8);
    blueIcon.iconAnchor = new GPoint(3, 8);
    blueIcon.infoWindowAnchor = new GPoint(3, 2);
    blueIcon.infoShadowAnchor = new GPoint(6, 6);
  }

  markerOptions = { icon:blueIcon };

  for (var i=0; i < pois.length; i++) {
    map.removeOverlay(pois[i]);
  }
  for (var i=0; i < poisinfo.length; i++) {
    pois[i]=new GMarker(new GLatLng(poisinfo[i][0],poisinfo[i][1]), markerOptions);
  }

}</pre>
<p>And, the <strong>showSelectedPois()</strong> method adds markers to the pois array in the map:</p>
<pre class="prettyprint">
function showSelectedPois() {
  for (var i=0; i < pois.length &amp;&amp; overlay; i++) {
    var item=pois[i].getLatLng();
    if (overlay.getBounds().containsLatLng(item)) {
      map.addOverlay(pois[i]);
    }
  }
}</pre>
<p>You can <a href="/googlemaps/test3.html">try</a> this example or <a href="/googlemaps/test3.zip">download</a> the code!</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;title=Playing+with+the+size+of+markers" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;title=Playing+with+the+size+of+markers" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;title=Playing+with+the+size+of+markers" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;title=Playing+with+the+size+of+markers&amp;description=Playing+with+the+size+of+markers" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;bm_description=Playing+with+the+size+of+markers" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;title=Playing+with+the+size+of+markers" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;title=Playing+with+the+size+of+markers" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/&amp;t=Playing+with+the+size+of+markers" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2007/11/25/playing-with-the-size-of-markers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The boundingbox problem</title>
		<link>http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/</link>
		<comments>http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 12:01:47 +0000</pubDate>
		<dc:creator>arcturus</dc:creator>
		
		<category><![CDATA[google]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[maps]]></category>

		<category><![CDATA[boundingbox]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/</guid>
		<description><![CDATA[Again with google maps, now we are going to talk about the bounding box problem.
The google api provides the function containsBounds:


containsPoint(point)


Returns true if the rectangular area (inclusively) contains       the pixel   coordinates. (Since 2.88)


The problem is very simple, we wanna check points of interest inside the polygon, not [...]]]></description>
			<content:encoded><![CDATA[<p>Again with google maps, now we are going to talk about the bounding box problem.</p>
<p>The google api provides the function <em>containsBounds</em>:</p>
<table style="width: 90%" summary="class GBounds - Methods">
<tr class="even">
<td class="code">containsPoint(<span class="type" title="type:  GPoint">point</span>)</td>
<td class="code"><span class="nomatch"><br />
</span></td>
<td>Returns <code><span class="nomatch">true</span></code> if the rectangular area (inclusively) contains       the pixel   coordinates. (Since 2.88)</td>
</tr>
</table>
<p>The problem is very simple, we wanna check points of interest inside the polygon, not the rectangular area that includes it.</p>
<p align="center"><img src="http://code.nosvamosdetapas.com/wp-content/uploads/2007/11/boundingbox.png" alt="boundingbox" /></p>
<p>We have solved this problem learning how to extend the GPolygon class with a method Contains that does what we want. You can see more examples of extending this class from this <a href="http://econym.googlepages.com/epoly.htm" title="extend_gpolygon" target="_blank">link</a>.</p>
<p>Here is the code we used:</p>
<pre class="prettyprint">
GPolygon.prototype.contains = function(point) { var j=0;

var oddNodes = false;

var x = point.lng();

var y = point.lat();

for (var i=0; i < this.getVertexCount(); i++) {

   j++;

   if (j == this.getVertexCount()) {j = 0;}   if (((this.getVertex(i).lat() < y)
         &amp;&amp; (this.getVertex(j).lat() >= y))

         || ((this.getVertex(j).lat() < y) &amp;&amp; (this.getVertex(i).lat() >= y))) {

              if ( this.getVertex(i).lng() + (y - this.getVertex(i).lat())

                   / (this.getVertex(j).lat()-this.getVertex(i).lat())

                  * (this.getVertex(j).lng() - this.getVertex(i).lng())>x){>

                       oddNodes = !oddNodes;

              }

    }

}

return oddNodes;

}</pre>
<p>Of course you can test this code <a href="http://code.nosvamosdetapas.com/googlemaps/test2.html" title="test2" target="_blank">here</a> and download it <a href="http://code.nosvamosdetapas.com/googlemaps/test2.zip" title="download_test2" target="_blank">here</a>.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;title=The+boundingbox+problem" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;title=The+boundingbox+problem" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;title=The+boundingbox+problem" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;title=The+boundingbox+problem&amp;description=The+boundingbox+problem" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;bm_description=The+boundingbox+problem" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;title=The+boundingbox+problem" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;title=The+boundingbox+problem" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/&amp;t=The+boundingbox+problem" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2007/11/19/the-boundingbox-problem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>First test with googlemaps</title>
		<link>http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/</link>
		<comments>http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 20:28:19 +0000</pubDate>
		<dc:creator>arcturus</dc:creator>
		
		<category><![CDATA[google]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[maps]]></category>

		<category><![CDATA[polygon]]></category>

		<guid isPermaLink="false">http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/</guid>
		<description><![CDATA[Hi all,
this is the first example from a serie of tests written to probe the googlemaps capabilities.
This example is quite simple, to draw a circunference in the map, with a center point and a radius:

Well, first of all, the google maps api does not draw circles, so, how is it that we see that circle [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>this is the first example from a serie of tests written to probe the googlemaps capabilities.</p>
<p>This example is quite simple, to draw a circunference in the map, with a center point and a radius:</p>
<p align="center"><img src="http://code.nosvamosdetapas.com/wp-content/uploads/2007/11/mapa0.png" alt="mapa0.png" /></p>
<p align="left">Well, first of all, the google maps api does not draw circles, so, how is it that we see that circle on the map?</p>
<p align="left">We are using here the solution provided by <a href="http://nuppineulat.blogspot.com/" title="esa" target="_blank">Esa</a> from Helsinki. He has written a function that draws a polygon simulating a circunference, you can specify the number of polygon edges, better accuracy with more edges. Here is  code:</p>
<p align="left">&nbsp;</p>
<pre class="prettyprint">
function drawCircle(center, radius, nodes, liColor,
                           liWidth, liOpa, fillColor, fillOpa){

//http://esa.ilmari.googlepages.com/circle.htm

//calculating km/degree

var latConv = center.distanceFrom(new GLatLng(center.lat()
                                               +0.1, center.lng()))/100;

var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()
                                               +0.1))/100;

//Loop

var points = [];

var step = parseInt(360/nodes)||10;

for(var i=0; i<=360; i+=step) {

  var pint = new GLatLng(center.lat() + (radius/latConv *
                   Math.cos(i * Math.PI/180)), center.lng() +
                   (radius/lngConv * Math.sin(i * Math.PI/180)));

  points.push(pint);

  //bounds.extend(pint); //this is for fit function

}

fillColor = fillColor||liColor||"#2b82bd";

liWidth = liWidth||2;

var poly = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa);

map.addOverlay(poly);

return poly;

}</pre>
<p>Now adding some more functionality to the example from Esa, let´s draw a animation of an circunference growing until it reaches the whole area.</p>
<pre class="prettyprint">
function drawAnimation(distance){

 timerStep = 0;

 timerId = setTimeout("drawAnimationAux("+distance+")",100);

}

function drawAnimationAux(distance){

 if (overlay)

   map.removeOverlay(overlay);

 var newRadius = distance/10.0 * (timerStep +1);

 overlay = drawCircle(actualPoint, newRadius, 30);

 timerStep++;

 if(timerStep<10)

    timerId = setTimeout("drawAnimationAux("+distance+")",100);

}</pre>
<p>You can see this example working <a href="http://code.nosvamosdetapas.com/googlemaps/test1.html" title="test1.html" target="_blank">here</a>, or <a href="http://code.nosvamosdetapas.com/googlemaps/test1.zip" title="download_test1" target="_blank">download</a> it.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/" title="Add to&nbsp;Bloglines"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/bloglines.png" title="Add to&nbsp;Bloglines" alt="Add to&nbsp;Bloglines" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;title=First+test+with+googlemaps" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;title=First+test+with+googlemaps" title="Add to&nbsp;digg"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/" title="Add to&nbsp;Facebook"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;title=First+test+with+googlemaps" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://ma.gnolia.com/bookmarklet/add?url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;title=First+test+with+googlemaps&amp;description=First+test+with+googlemaps" title="Add to&nbsp;Ma.gnolia"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/magnolia.png" title="Add to&nbsp;Ma.gnolia" alt="Add to&nbsp;Ma.gnolia" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;bm_description=First+test+with+googlemaps" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;title=First+test+with+googlemaps" title="Add to&nbsp;reddit"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;title=First+test+with+googlemaps" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/" title="Add to&nbsp;Technorati"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/&amp;t=First+test+with+googlemaps" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://meneame.net/submit.php?url=http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/" title="Add to&nbsp;Meneame"><img class="social_img" src="http://code.nosvamosdetapas.com/wp-content/plugins/social_bookmarks/images/meneame.png" title="Add to&nbsp;Meneame" alt="Add to&nbsp;Meneame" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://code.nosvamosdetapas.com/2007/11/15/first-test-with-googlemaps/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
