<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog::Log &#187; api</title>
	<atom:link href="http://www.stpe.se/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stpe.se</link>
	<description>Not a blog, more a log.</description>
	<lastBuildDate>Wed, 02 Jun 2010 13:01:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Virtual Earth point in bounding box test</title>
		<link>http://www.stpe.se/2009/02/virtual-earth-point-in-bounding-box-test/</link>
		<comments>http://www.stpe.se/2009/02/virtual-earth-point-in-bounding-box-test/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 14:28:14 +0000</pubDate>
		<dc:creator>stefan</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[virtual earth]]></category>

		<guid isPermaLink="false">http://www.stpe.se/?p=102</guid>
		<description><![CDATA[I&#8217;m currently working with the Microsoft Virtual Earth SDK and wanted to test if a point is inside a box as where coordinates are specified using latitude and longitude. It appears there are no built in function the API that does this, so this is what I came up with. Please note the special case [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working with the Microsoft Virtual Earth SDK and wanted to test if a point is inside a box as where coordinates are specified using latitude and longitude.</p>
<p>It appears there are no built in function the API that does this, so this is what I came up with. Please note the special case where the bounding box overlaps the 180th degree longitude.</p>
<pre class="brush: jscript;">
/**
* Returns true if point is in rectangle.
*
* @param {VELatLong} point Point to check.
* @param {VELatLongRectangle} rect Bounding box.
*/
function isPointInRect(point, rect) {
    return ( (rect.TopLeftLatLong.Longitude &lt;= rect.BottomRightLatLong.Longitude &amp;&amp; // longitude
              rect.TopLeftLatLong.Longitude &lt;= point.Longitude &amp;&amp;
              rect.BottomRightLatLong.Longitude &gt;= point.Longitude)
           || (rect.TopLeftLatLong.Longitude &gt; rect.BottomRightLatLong.Longitude &amp;&amp;  // longitude crosses 180 degrees
              rect.TopLeftLatLong.Longitude &gt;= point.Longitude &amp;&amp;
              rect.BottomRightLatLong.Longitude &lt;= point.Longitude) )
           &amp;&amp; (rect.TopLeftLatLong.Latitude &gt;= point.Latitude &amp;&amp;     // latitude
              rect.BottomRightLatLong.Latitude &lt;= point.Latitude);
}
</pre>
<p>This may be used, among many things, to test if a pushpin shape is within the current map view, and if it isn&#8217;t the map is panned to make it visible:</p>
<pre class="brush: jscript;">
var point = shape.GetPoints()[0];
if (!isPointInRect(point, map.GetMapView())) {
    map.PanToLatLong(point);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.stpe.se/2009/02/virtual-earth-point-in-bounding-box-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
