<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Ruler for Google Maps v3 to measure distance on map</title>
	<atom:link href="http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/</link>
	<description>code snippets, classes and other stuff for developers</description>
	<lastBuildDate>Fri, 18 Nov 2011 12:00:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Francisco</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-30940</link>
		<dc:creator>Francisco</dc:creator>
		<pubDate>Fri, 04 Nov 2011 22:28:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-30940</guid>
		<description>thanks a lot</description>
		<content:encoded><![CDATA[<p>thanks a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-26733</link>
		<dc:creator>Marius</dc:creator>
		<pubDate>Thu, 29 Sep 2011 12:11:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-26733</guid>
		<description>I am a dumb ass - It still had the old version in cache, so make sure you clear the cache so it gets the new js file, then it works :)</description>
		<content:encoded><![CDATA[<p>I am a dumb ass &#8211; It still had the old version in cache, so make sure you clear the cache so it gets the new js file, then it works :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-26732</link>
		<dc:creator>Marius</dc:creator>
		<pubDate>Thu, 29 Sep 2011 12:08:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-26732</guid>
		<description>Sorry, I lied. It works when i test it locally, but does not work when i put it on the live server :(</description>
		<content:encoded><![CDATA[<p>Sorry, I lied. It works when i test it locally, but does not work when i put it on the live server :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-26730</link>
		<dc:creator>Marius</dc:creator>
		<pubDate>Thu, 29 Sep 2011 12:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-26730</guid>
		<description>I changed the script a bit, and now you can remove the ruler. Simply pass a &#039;true&#039; or &#039;false&#039; to the addruler call

var ruler1;
var ruler2;
var ruler1label;
var ruler2label;
var rulerpoly;

function addruler(remove) {

    if (remove) {
        google.maps.event.clearListeners(ruler1, &#039;drag&#039;);
        ruler1.setMap(null);
        google.maps.event.clearListeners(ruler2, &#039;drag&#039;);
        ruler2.setMap(null);
        ruler1label.setMap(null);
        ruler2label.setMap(null);
        rulerpoly.setMap(null);
    }
    else {
        ruler1 = new google.maps.Marker({
            position: map.getCenter(),
            map: map,
            title: &#039;Starting Point&#039;,
            draggable: true
        });

        ruler2 = new google.maps.Marker({
            position: map.getCenter(),
            map: map,
            title: &#039;End Point&#039;,
            draggable: true
        });
        ruler1label = new Label({ map: map });
        ruler2label = new Label({ map: map });
        ruler1label.bindTo(&#039;position&#039;, ruler1, &#039;position&#039;);
        ruler2label.bindTo(&#039;position&#039;, ruler2, &#039;position&#039;);

        rulerpoly = new google.maps.Polyline({
            path: [ruler1.position, ruler2.position],
            strokeColor: &quot;#FFFF00&quot;,
            strokeOpacity: .7,
            strokeWeight: 7
        });

        rulerpoly.setMap(map);

        ruler1label.set(&#039;text&#039;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
        ruler2label.set(&#039;text&#039;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));


        google.maps.event.addListener(ruler1, &#039;drag&#039;, function() {
            rulerpoly.setPath([ruler1.getPosition(), ruler2.getPosition()]);
            ruler1label.set(&#039;text&#039;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
            ruler2label.set(&#039;text&#039;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
        });

        google.maps.event.addListener(ruler2, &#039;drag&#039;, function() {
            rulerpoly.setPath([ruler1.getPosition(), ruler2.getPosition()]);
            ruler1label.set(&#039;text&#039;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
            ruler2label.set(&#039;text&#039;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));
        });
    }

}

function distance(lat1,lon1,lat2,lon2) {
	var R = 6371; // km (change this constant to get miles)
	var dLat = (lat2-lat1) * Math.PI / 180;
	var dLon = (lon2-lon1) * Math.PI / 180; 
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
		Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) * 
		Math.sin(dLon/2) * Math.sin(dLon/2); 
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
	var d = R * c;
	if (d&gt;1) return Math.round(d)+&quot;km&quot;;
	else if (d&lt;=1) return Math.round(d*1000)+&quot;m&quot;;
	return d;
}</description>
		<content:encoded><![CDATA[<p>I changed the script a bit, and now you can remove the ruler. Simply pass a &#8216;true&#8217; or &#8216;false&#8217; to the addruler call</p>
<p>var ruler1;<br />
var ruler2;<br />
var ruler1label;<br />
var ruler2label;<br />
var rulerpoly;</p>
<p>function addruler(remove) {</p>
<p>    if (remove) {<br />
        google.maps.event.clearListeners(ruler1, &#8216;drag&#8217;);<br />
        ruler1.setMap(null);<br />
        google.maps.event.clearListeners(ruler2, &#8216;drag&#8217;);<br />
        ruler2.setMap(null);<br />
        ruler1label.setMap(null);<br />
        ruler2label.setMap(null);<br />
        rulerpoly.setMap(null);<br />
    }<br />
    else {<br />
        ruler1 = new google.maps.Marker({<br />
            position: map.getCenter(),<br />
            map: map,<br />
            title: &#8216;Starting Point&#8217;,<br />
            draggable: true<br />
        });</p>
<p>        ruler2 = new google.maps.Marker({<br />
            position: map.getCenter(),<br />
            map: map,<br />
            title: &#8216;End Point&#8217;,<br />
            draggable: true<br />
        });<br />
        ruler1label = new Label({ map: map });<br />
        ruler2label = new Label({ map: map });<br />
        ruler1label.bindTo(&#8216;position&#8217;, ruler1, &#8216;position&#8217;);<br />
        ruler2label.bindTo(&#8216;position&#8217;, ruler2, &#8216;position&#8217;);</p>
<p>        rulerpoly = new google.maps.Polyline({<br />
            path: [ruler1.position, ruler2.position],<br />
            strokeColor: &#8220;#FFFF00&#8243;,<br />
            strokeOpacity: .7,<br />
            strokeWeight: 7<br />
        });</p>
<p>        rulerpoly.setMap(map);</p>
<p>        ruler1label.set(&#8216;text&#8217;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));<br />
        ruler2label.set(&#8216;text&#8217;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));</p>
<p>        google.maps.event.addListener(ruler1, &#8216;drag&#8217;, function() {<br />
            rulerpoly.setPath([ruler1.getPosition(), ruler2.getPosition()]);<br />
            ruler1label.set(&#8216;text&#8217;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));<br />
            ruler2label.set(&#8216;text&#8217;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));<br />
        });</p>
<p>        google.maps.event.addListener(ruler2, &#8216;drag&#8217;, function() {<br />
            rulerpoly.setPath([ruler1.getPosition(), ruler2.getPosition()]);<br />
            ruler1label.set(&#8216;text&#8217;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));<br />
            ruler2label.set(&#8216;text&#8217;, distance(ruler1.getPosition().lat(), ruler1.getPosition().lng(), ruler2.getPosition().lat(), ruler2.getPosition().lng()));<br />
        });<br />
    }</p>
<p>}</p>
<p>function distance(lat1,lon1,lat2,lon2) {<br />
	var R = 6371; // km (change this constant to get miles)<br />
	var dLat = (lat2-lat1) * Math.PI / 180;<br />
	var dLon = (lon2-lon1) * Math.PI / 180;<br />
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +<br />
		Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) *<br />
		Math.sin(dLon/2) * Math.sin(dLon/2);<br />
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));<br />
	var d = R * c;<br />
	if (d&gt;1) return Math.round(d)+&#8221;km&#8221;;<br />
	else if (d&lt;=1) return Math.round(d*1000)+&quot;m&quot;;<br />
	return d;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-26543</link>
		<dc:creator>Marius</dc:creator>
		<pubDate>Tue, 27 Sep 2011 19:33:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-26543</guid>
		<description>Very nice, i also though want to know how to remove the ruler ?</description>
		<content:encoded><![CDATA[<p>Very nice, i also though want to know how to remove the ruler ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francisco</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-24220</link>
		<dc:creator>Francisco</dc:creator>
		<pubDate>Mon, 05 Sep 2011 19:04:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-24220</guid>
		<description>how do you remove a ruler,,, can you helps us</description>
		<content:encoded><![CDATA[<p>how do you remove a ruler,,, can you helps us</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Web Design Huntersville</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-22403</link>
		<dc:creator>Web Design Huntersville</dc:creator>
		<pubDate>Tue, 16 Aug 2011 13:30:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-22403</guid>
		<description>How do you remove a ruler?</description>
		<content:encoded><![CDATA[<p>How do you remove a ruler?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pani100</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-19108</link>
		<dc:creator>pani100</dc:creator>
		<pubDate>Fri, 15 Jul 2011 09:35:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-19108</guid>
		<description>Really good and handy code.
If i wanted to change the distance to miles would this be correct?
function distance(lat1,lon1,lat2,lon2) {
	var R = 3959; // km (change this constant to get miles. 3959 for m, 6371 for km also change 1000 to 1760)
	var dLat = (lat2-lat1) * Math.PI / 180;
	var dLon = (lon2-lon1) * Math.PI / 180; 
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
		Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) * 
		Math.sin(dLon/2) * Math.sin(dLon/2); 
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
	var d = R * c;
	if (d&gt;1) return Math.round(d)+&quot;miles&quot;;
	else if (d&lt;=1) return Math.round(d*1760)+&quot;yards&quot;;
	return d;

Regards
Pani</description>
		<content:encoded><![CDATA[<p>Really good and handy code.<br />
If i wanted to change the distance to miles would this be correct?<br />
function distance(lat1,lon1,lat2,lon2) {<br />
	var R = 3959; // km (change this constant to get miles. 3959 for m, 6371 for km also change 1000 to 1760)<br />
	var dLat = (lat2-lat1) * Math.PI / 180;<br />
	var dLon = (lon2-lon1) * Math.PI / 180;<br />
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +<br />
		Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) *<br />
		Math.sin(dLon/2) * Math.sin(dLon/2);<br />
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));<br />
	var d = R * c;<br />
	if (d&gt;1) return Math.round(d)+&#8221;miles&#8221;;<br />
	else if (d&lt;=1) return Math.round(d*1760)+&quot;yards&quot;;<br />
	return d;</p>
<p>Regards<br />
Pani</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: phicarre</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-13865</link>
		<dc:creator>phicarre</dc:creator>
		<pubDate>Tue, 24 May 2011 12:10:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-13865</guid>
		<description>Hello,
If I attribute an icon to the rulers then the behaviour changes !
How to change the standard icons ?

Thank you.</description>
		<content:encoded><![CDATA[<p>Hello,<br />
If I attribute an icon to the rulers then the behaviour changes !<br />
How to change the standard icons ?</p>
<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: piero</title>
		<link>http://www.barattalo.it/2009/12/19/ruler-for-google-maps-v3-to-measure-distance-on-map/comment-page-1/#comment-5703</link>
		<dc:creator>piero</dc:creator>
		<pubDate>Sat, 05 Feb 2011 14:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.barattalo.it/?p=229#comment-5703</guid>
		<description>Excellent. Good job: my congratulation. 
It would useful also to have a couple of additional features:
1)replace the couple of labels with a single label placed in the middle of the ruler line, alway on top (I tried using zIndex with no success? any idea ?) 
2)the rule line binded to the objects you&#039;re measuring the distance. Suppose we would like to continously track the distance changes among a couple of moving markers (i.e. vehicles). 

PG Ornolio</description>
		<content:encoded><![CDATA[<p>Excellent. Good job: my congratulation.<br />
It would useful also to have a couple of additional features:<br />
1)replace the couple of labels with a single label placed in the middle of the ruler line, alway on top (I tried using zIndex with no success? any idea ?)<br />
2)the rule line binded to the objects you&#8217;re measuring the distance. Suppose we would like to continously track the distance changes among a couple of moving markers (i.e. vehicles). </p>
<p>PG Ornolio</p>
]]></content:encoded>
	</item>
</channel>
</rss>

