<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2559668977390861004</id><updated>2012-01-26T05:56:24.430-08:00</updated><category term='rest web'/><category term='WP7Contrib  Bing Maps WP7'/><category term='Silverlight Installation'/><category term='Coding Building CI Testing'/><category term='WP7 WP7Contrib CodePlex Bing Maps Development'/><category term='Performance'/><category term='WP7 Bing Maps Development UK Crime Clustering'/><category term='Coding C#'/><category term='NoSQL RavenDB Azure Development'/><category term='Agile Courage'/><category term='nHbiernate Repository Pattern Criteria'/><category term='WP7 WP7Contrib CodePlex ObservableCollection'/><category term='WP7 ORM Databases performance'/><category term='DDD Domain Events Auditing nHibernate'/><category term='WP7 WP7Contrib Phone Maps'/><category term='UI'/><category term='Azure IIS RESTful development'/><category term='WP7 WP7Contrib ILMerge .Net'/><category term='Development Process'/><category term='TDD IoC DI'/><category term='WP7 feedback development app store'/><category term='Development Coding'/><category term='threading'/><category term='WP7Dev'/><category term='WP7 Bing Maps Development UK Crime'/><category term='WP7 sqlite performance development'/><category term='DDD Entities Value Objects'/><category term='coding C# IoC StructureMap'/><category term='Debugging'/><category term='CultureInfo'/><category term='DDD'/><category term='WP7Contrib WP7 Url Development Rx'/><category term='WP7 WP7Contrib CodePlex'/><category term='nHibernate Auditing Design Fluent'/><category term='TDD Mocking'/><category term='REST Distributed-Systems'/><category term='wcf'/><category term='Coding'/><category term='WP7 MSBuild'/><category term='web services mobile devices data'/><category term='Coding REST Knowledge'/><category term='WP7 Bing Maps Development UK Polygons Clustering Performance'/><category term='WP7 Cultures C#'/><category term='Coding Functional-Programming'/><category term='ReadOnlyCollections'/><category term='nHibnerate Entities Events Listeners'/><category term='Jobs Development'/><category term='WP7Contrib'/><category term='WP7 SilverlightSerializer C#'/><category term='Fun Coding Duct-Tape'/><category term='WP7'/><category term='FindaPad Property Rental Windows Phone 7 Mobile Devices'/><category term='Caching'/><category term='REST HTTP'/><category term='WP7 WP7Contrib Bing Maps Polygon Development'/><category term='Developement'/><category term='OO'/><category term='FINDaPAD'/><category term='RavenDB IIS 7.5 Development'/><category term='WP7 cryptography bouncy castle'/><category term='WP7 WP7Contrib SilverlightSerializer C#'/><category term='Development'/><category term='Design Patterns Databases Auditing'/><category term='Rants'/><category term='Agile'/><category term='WP7Contrib WP7 HTTP Compression'/><category term='WP7Contrib WP7 Geo-Location development C#'/><category term='Bing Maps'/><category term='WP7 Javascript web browser'/><category term='Observations'/><category term='TDD Team Observation'/><category term='WP7 Bing Maps Development Network HTTP'/><category term='Coding TDD Refactoring Agile'/><category term='Process'/><category term='WP7 WP7Contrib Bing Maps Development'/><category term='WP7 Serialisation'/><category term='Coding Services'/><category term='DDD Coaching'/><category term='Silverlight'/><category term='CodePlex'/><category term='Serialization'/><category term='Bounded Context'/><category term='MSDN Coding'/><title type='text'>Awkward Coder</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>85</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-3668723600984365782</id><published>2011-12-06T06:07:00.001-08:00</published><updated>2011-12-06T06:30:49.345-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='NoSQL RavenDB Azure Development'/><title type='text'>RavenDB - locked database base when running Azure emulator</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Thought I'd note this down for anyone observing this in the future - this was purely down to user (me) error!&lt;br /&gt;&lt;br /&gt;If you ever find yourself using the embedded version of RavenDB in an asp.net based azure hosted service running in the azure emulator locally&amp;nbsp;don't play around with azure instance settings as it can f**k-up royally and cause you no end of pain with your RavenDB instance.&lt;br /&gt;&lt;br /&gt;Specifically if you change the number of instance to anything other than 1 you start to observe race conditions in your app. Always keep the instance count to 1 when running in the emulator locally:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gO2zMZX4Low/Tt4kEowfKBI/AAAAAAAAAW8/-TZp18gfs-4/s1600/raven+locked+database+azure+1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-gO2zMZX4Low/Tt4kEowfKBI/AAAAAAAAAW8/-TZp18gfs-4/s1600/raven+locked+database+azure+1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;If you don't you start to receive exceptions like the following:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-7e4CFM5xHKk/Tt4kzLbdtNI/AAAAAAAAAXU/ddI-Grx2EIM/s1600/raven+locked+database+azure.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-7e4CFM5xHKk/Tt4kzLbdtNI/AAAAAAAAAXU/ddI-Grx2EIM/s1600/raven+locked+database+azure.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;IT took me about an hour to figure this out, I only realised when I looked at the azure compute storage emulator and saw 2 instances running simultaneously. I would have thought these would be using&amp;nbsp;separate&amp;nbsp;physical database instances but after thinking about this it became obvious they weren't - the IIS instances were virtualised but the physical folder structure wasn't.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Sz0EH2YVLSg/Tt4mqjZXTiI/AAAAAAAAAXc/2EfqIV20piY/s1600/raven+locked+database+azure+2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-Sz0EH2YVLSg/Tt4mqjZXTiI/AAAAAAAAAXc/2EfqIV20piY/s1600/raven+locked+database+azure+2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-3668723600984365782?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/3668723600984365782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/12/ravendb-locked-database-base-when.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/3668723600984365782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/3668723600984365782'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/12/ravendb-locked-database-base-when.html' title='RavenDB - locked database base when running Azure emulator'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-gO2zMZX4Low/Tt4kEowfKBI/AAAAAAAAAW8/-TZp18gfs-4/s72-c/raven+locked+database+azure+1.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-5159590475611700661</id><published>2011-12-06T05:31:00.001-08:00</published><updated>2011-12-06T05:59:43.821-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Azure IIS RESTful development'/><title type='text'>Configuring default page for azure service</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Been playing around with Azure for a week or so now and I'm starting to get my head round it, to be honest it ain't that difficult. &lt;a href="https://twitter.com/#!/RichGee"&gt;@RichGee&lt;/a&gt; &amp;amp; I are going to be deploying RESTful services into the cloud for our shiney ninja project and whilst we are spiking these out I wanted to be able to set the default page, you know something like 'default.html'.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now this was easy when hosting a service in IIS, all you had to do was specify the default document types:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-NQeYrGMaQCY/Tt4csF4skII/AAAAAAAAAWk/XbLER1UnfCE/s1600/default+document.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="246" src="http://1.bp.blogspot.com/-NQeYrGMaQCY/Tt4csF4skII/AAAAAAAAAWk/XbLER1UnfCE/s640/default+document.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;But in azure there isn't any visible way to access IIS from the management tools, you only have access to the 'Hosted Services' console:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-fASyf44VBQc/Tt4d1XVcPOI/AAAAAAAAAWs/nR3A2NuCcCY/s1600/default+document+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="304" src="http://1.bp.blogspot.com/-fASyf44VBQc/Tt4d1XVcPOI/AAAAAAAAAWs/nR3A2NuCcCY/s640/default+document+2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;I&amp;nbsp;suppose&amp;nbsp;you could remote onto the virtual box and set it up in IIS, but that feels overly complicated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;There must be any easier way?&lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There is if you are using asp.net, the&amp;nbsp;&lt;system.webserver&gt; element in the web.config. This allows you specify the default document at design time and will be injected into IIS when the web service\site is installed into IIS by azure:&lt;/system.webserver&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-xF8aZaqjQEI/Tt4fLn8bUEI/AAAAAAAAAW0/3iG2QmtK7uQ/s1600/default+document+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-xF8aZaqjQEI/Tt4fLn8bUEI/AAAAAAAAAW0/3iG2QmtK7uQ/s1600/default+document+3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;More info can be found in MSDN &lt;a href="http://msdn.microsoft.com/en-us/library/bb763179.aspx"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-5159590475611700661?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/5159590475611700661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/12/configuring-default-page-for-azure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/5159590475611700661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/5159590475611700661'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/12/configuring-default-page-for-azure.html' title='Configuring default page for azure service'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-NQeYrGMaQCY/Tt4csF4skII/AAAAAAAAAWk/XbLER1UnfCE/s72-c/default+document.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-8314717237068983300</id><published>2011-12-01T07:54:00.001-08:00</published><updated>2011-12-01T08:49:04.643-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 feedback development app store'/><category scheme='http://www.blogger.com/atom/ns#' term='FINDaPAD'/><title type='text'>Getting app feedback from windowsphone.com</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I was chatting with my good friend Denis (&lt;a href="https://twitter.com/#!/dhaman"&gt;@dhaman&lt;/a&gt;) about user feedback for the apps he's produced for the iPhone &amp;amp; droid app stores and just like the WP7 app store they all fall short in supporting&amp;nbsp;your&amp;nbsp;app once released out into the wild. I was also reading the final post in the '&lt;i&gt;&lt;a href="http://www.jeffblankenburg.com/"&gt;31 days of mango...&lt;/a&gt;&lt;/i&gt;' by&amp;nbsp;&lt;a href="https://twitter.com/#!/jeffblankenburg"&gt;@jeffblankenburg&lt;/a&gt;&amp;nbsp;and he talks about promoting your app, he mentions the great work Nick (&lt;a href="http://www.twitter.com/spacescape"&gt;@spacescape&lt;/a&gt;) did originally for &lt;a href="http://www.windowsphone.com/en-GB/apps/2d496451-8fd3-426f-b4dd-3d323781931d"&gt;FINDaPAD&lt;/a&gt;&amp;nbsp;in producing a template you can use to provide a bespoke site for WP7 app - Nick pushed this out to codeplex &lt;a href="http://wp7appsite.codeplex.com/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Denis pointed out he started to explicitly put a feedback mechanism in the app blurb, ideally at the top. Initially I thought I don't need this, we've got &lt;a href="http://findapad.biz/"&gt;http://findapad.biz&lt;/a&gt; with feedback via &lt;a href="http://uservoice.com/"&gt;uservoice&lt;/a&gt;, but then I realised there isn't any way for a user viewing FINDaPAD in the app store to get in touch with us. This is a piece of functionality that should be in the app store and I don't mean a forum like feature to discuss the review\rating by a dissatisified user (1 star rating for FINDaPAD) I mean the ability to provide a contact point for any user to talk to you.&lt;br /&gt;&lt;br /&gt;As you can see from the screenshot below they don't even provide anyway to show a support URL or email. I would have expected something down the left&amp;nbsp;hand-side.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-l8l10h-u964/TterPJlWgDI/AAAAAAAAAWU/LKiBL81rI4c/s1600/feedbacki+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-l8l10h-u964/TterPJlWgDI/AAAAAAAAAWU/LKiBL81rI4c/s1600/feedbacki+1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I don't really expect the app store to get a make over until Windows 8 platform is released (including to the phone). So what I am going to do to help us get better feedback in the mean time is put an explicit message in the blurb. Something like:&lt;br /&gt;&lt;br /&gt;'&lt;i&gt;We really want to hear from you, get in touch via feedback @ http://findapad.biz&lt;/i&gt;'&lt;br /&gt;&lt;br /&gt;Now where this should be&amp;nbsp;positioned&amp;nbsp;is the difficult question, I'll try near the bottom at first and see what happens.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-8314717237068983300?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/8314717237068983300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/12/getting-app-feedback-from.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8314717237068983300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8314717237068983300'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/12/getting-app-feedback-from.html' title='Getting app feedback from windowsphone.com'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-l8l10h-u964/TterPJlWgDI/AAAAAAAAAWU/LKiBL81rI4c/s72-c/feedbacki+1.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-2811826802340972704</id><published>2011-11-28T09:53:00.001-08:00</published><updated>2011-11-28T13:52:15.399-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web services mobile devices data'/><title type='text'>Observations on web service design for mobile devices</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This post was prompted by my use of back end third party services for the &lt;a href="http://findapad.biz/"&gt;FINDaPAD &lt;/a&gt;app and my recent set of &lt;a href="http://awkwardcoder.blogspot.com/2011/09/how-many-pins-can-bing-maps-handle-in.html"&gt;posts&lt;/a&gt; about push pins and Bing Maps control. I want to explore the affect the design of the back end services can have on a mobile app UX &amp;amp; UI design.&lt;br /&gt;&lt;br /&gt;For FINDaPAD we make use of two sets of third party services, &lt;a href="http://www.nestoria.co.uk/help/api"&gt;Nestoria&lt;/a&gt; &amp;amp; &lt;a href="http://www.police.uk/api/docs/"&gt;UK Crime API&lt;/a&gt;. Nestoria is a property search service for the UK and other countries whilst UK Crime API provides crime information for England &amp;amp; Wales, we use the second to generate crime stats for a local area when viewing a property in FINDaPAD.&lt;br /&gt;&lt;br /&gt;Even though&amp;nbsp;Nestoria&amp;nbsp;claim on their website '&lt;i&gt;The API is very much a work in progress.' &lt;/i&gt;I believe this be a well thought out API from a consumers perspective, it has a compact data schema (JSON or XML) and it&amp;nbsp;enforces a pagination convention on the&amp;nbsp;consumer&amp;nbsp;which has a bigger benefit for mobile app development than for full blown desktop for the simple reason of CPU performance and power consumption. We use two APIs from Nestoria, one for property details and the other for average property prices - one HTTP GET request for one set of results. It has&amp;nbsp;well defined pagination API which limits the maximum page size to 50.&lt;br /&gt;&lt;br /&gt;Shown below is the performance cost of making a HTTP GET request against&amp;nbsp;Nestoria&amp;nbsp;on a tethered WP7 device - it takes approximately 3.7 seconds to request the first 50 properties, decode the JSON and map into a domain model. The relationship between the number of properties downloaded and the time taken to download is relatively linear and predictable and this fact is import when designing how your UI reacts when downloading data - whether it sits there with a progress bar or allows the user to perform other actions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ny8ocYEwGuM/TtPu6j_XoBI/AAAAAAAAAV8/1AjJif6yctw/s1600/service+design+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-ny8ocYEwGuM/TtPu6j_XoBI/AAAAAAAAAV8/1AjJif6yctw/s1600/service+design+2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The UK Police API is a less mature API having been around for about a year, it allows you to query for data by several different criteria.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;In FINDaPAD we have to use two separate API calls to get the information we want - two HTTP GET requests for one set of results. First we have to make a HTTP&amp;nbsp;GET&amp;nbsp;request with our geo-location to get the police force &amp;amp; neighbourhood values and then a second HTTP&amp;nbsp;GET&amp;nbsp;request with the result from the first to get the crime stats for the current geo-location. Now this isn't a problem per-se for FINDaPAD because we request the crime stats asynchronously whilst we are trickling the property data from Nestoria to the UI so the user experience is a seem less transition from the details of property to the crime stats for the local area. Ideally this would have been done as a single web request not only from a performance point of view but from a cost - if you're paying for your data plan on your mobile device then you would have incurred a greater cost.&lt;br /&gt;&lt;br /&gt;In my '&lt;i&gt;How many pins...&lt;/i&gt;' I was using a UK Police API to return all the crimes in a particular area, this was based on the idea of supplying a geo-location and it would return all the crimes occurring within a 1 mile radius for the last&amp;nbsp;calendar&amp;nbsp;month. This API call works great when tested from a desktop app or the WP7&amp;nbsp;emulator&amp;nbsp;because both have plenty of processor power, memory and network connectivity. But when running on a device it can be an issue because the returned data set has an unlimited size and the cost in time to transmit this down the wire, decode etc is unknown - fundamentally the API does not support pagination. This is best&amp;nbsp;demonstrated&amp;nbsp;by the following set of screen shots, searches for crimes in totally different locations, one a remote rural area and the other an urban inner city area:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-I97UaADdZpc/TtP6w0ShtBI/AAAAAAAAAWE/WZdAPKM1rEQ/s1600/service+design+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-I97UaADdZpc/TtP6w0ShtBI/AAAAAAAAAWE/WZdAPKM1rEQ/s1600/service+design+4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-zjVvj67jQl4/TtP60qLKlxI/AAAAAAAAAWM/8lDcicujI4A/s1600/service+design+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-zjVvj67jQl4/TtP60qLKlxI/AAAAAAAAAWM/8lDcicujI4A/s1600/service+design+5.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The first screen shot shows the cost to get all the crimes in a rural area (where there are no crimes) and the second in the urban inner city you can see how the elapsed time has increased, if the total crimes in the urban area increases I don't have anyway of calculating how long it would take to request and process going results and ultimately this could lead the user to abandon the app (and give it a bad rating!).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;So you might ask - Okay how would you do it then?&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;If I was going to keep the API endpoint the same - all crimes in a 1 mile radius. I would add pagination support so that I could trickle the data to UI as each request is&amp;nbsp;fulfilled. If I was going to change the API I would like the ability to specify a bounding rectangle so I could request only the visible crimes, this would also require pagination as the number of crimes could be even greater than the 1630 show above. Though there could be a downside to the second approach as this would make client caching more&amp;nbsp;problematic.&lt;br /&gt;&lt;br /&gt;Don't be under the impression I think the UK Police API is bad or wrongly implemented, I believe this APIs will mature over time as greater understand of how the data is being used.&lt;br /&gt;&lt;br /&gt;Remember not all publicly consumable web services are well suited for use with mobile devices.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-2811826802340972704?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/2811826802340972704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/observations-on-web-service-design-for.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/2811826802340972704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/2811826802340972704'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/observations-on-web-service-design-for.html' title='Observations on web service design for mobile devices'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-ny8ocYEwGuM/TtPu6j_XoBI/AAAAAAAAAV8/1AjJif6yctw/s72-c/service+design+2.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-4645452168238422234</id><published>2011-11-23T12:51:00.001-08:00</published><updated>2011-11-24T06:45:45.980-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 Bing Maps Development UK Crime Clustering'/><title type='text'>How many pins can Bing Maps handle in a WP7 app - part 3</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I've finally got round to finishing this 3 part series about manipulating push pins on the Bing Maps control in WP7 - the final part took longer than expected!&lt;br /&gt;&lt;br /&gt;In the &lt;a href="http://awkwardcoder.blogspot.com/2011/09/how-many-pins-can-bing-maps-handle-in.html"&gt;first&lt;/a&gt; part I showed what happens to memory usage and UI performance when you have to many pins to show and how virtualizing the pins can reduce and improve both of these. In the &lt;a href="http://awkwardcoder.blogspot.com/2011/10/how-many-pins-can-bing-maps-handle-in.html"&gt;second&lt;/a&gt; part I showed how you could optimise the HTTP calls to the back end services and how scrolling around the map control can be used to start and stop the requesting of more data.&lt;br /&gt;&lt;br /&gt;In this part what I want to show is how you can group &amp;amp; cluster pins and effectively remove the idea of using a pins completely but still convey the geo-location data to the user. I'll be using techniques described in the polygons &lt;a href="http://awkwardcoder.blogspot.com/2011/11/tessellating-shapes-on-top-of-bing-maps.html"&gt;posts&lt;/a&gt; I wrote previously to help with the grouping &amp;amp; clustering of pins.&lt;br /&gt;&lt;br /&gt;For this post like the&amp;nbsp;previous posts I'm going to be using the UK Police API for street level crime, see &lt;a href="http://www.police.uk/api/docs/method/crime-street/"&gt;here&lt;/a&gt;. This API gives a lot of data when used in an urban area like London&amp;nbsp;and I'll using a location based in London to show how grouping and clustering can&amp;nbsp;improve&amp;nbsp;the UI experience.&lt;br /&gt;&lt;br /&gt;At the end of part 2 we still had the same UI as part 1 but it was optimised for HTTP communication to the back end services - the first screen shot shows the map with no push pins and second shows the UI at the end of the second post:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-bnRM7u6q4j8/Ts1keInFZ2I/AAAAAAAAAUk/9GHyDsrf_ys/s1600/pins+3+-+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="577" src="http://1.bp.blogspot.com/-bnRM7u6q4j8/Ts1keInFZ2I/AAAAAAAAAUk/9GHyDsrf_ys/s640/pins+3+-+1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As you can see the second screenshot indicates there was 313 crimes in the visible bounding rectangle - what you can't gain from&amp;nbsp;interpreting&amp;nbsp;the data with pins is there are multiple crimes for the same location. Plus when there are a lot crimes we start to loose site of the map control it's self and this defeats the point of using the map control in the first place. I've also highlighted the memory usage and at the end of part 2 the memory usage was around 48 Mb which to be honest is rather high for such a simple task.&lt;br /&gt;&lt;br /&gt;What I did to get round these issues was to use a square polygon to represent a defined area of the visible map - very similar to the way I did this in the '&lt;i&gt;tessellating polygons&lt;/i&gt;' &lt;a href="http://awkwardcoder.blogspot.com/2011/11/tessellating-shapes-on-top-of-bing-maps.html"&gt;posts&lt;/a&gt;. I then calculated if a crime occurred within this defined area and if it did the crime was added to class representing the defined area ( class called 'CrimeShape'). The first screen shot below shows the same location zoomed out with no tessellation, the second shows the squares at this resolution. As you can see we can now show more crime data, well over 1000, but at this resolution it's still hard to gain a meaningful understanding. The third screen shot is the same place at a higher resolution:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-taLIrRA1A0Q/Ts1uiI3p12I/AAAAAAAAAUs/QKdVl-1-ezs/s1600/pins+3+-+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="398" src="http://2.bp.blogspot.com/-taLIrRA1A0Q/Ts1uiI3p12I/AAAAAAAAAUs/QKdVl-1-ezs/s640/pins+3+-+2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So now we've a reduced number of pins and an increased amount of crime data. What's interesting about the third screen shot is it appears there is a crime hot spot centred around the traffic junction (intersection) - 269 crimes. The memory usage is also much better, even on the second screen shot we're now peaking memory at half the previous implementation peak value.&lt;br /&gt;&lt;br /&gt;Drilling down further into the data by increasing the resolution of the map control (via the Zoom property) and&amp;nbsp;gradually&amp;nbsp;reducing the square area size I get the following set of screen shots:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Axze6naVnxQ/Ts1zNre_CjI/AAAAAAAAAU0/s-nt1AXWpV8/s1600/pins+3+-+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="238" src="http://4.bp.blogspot.com/-Axze6naVnxQ/Ts1zNre_CjI/AAAAAAAAAU0/s-nt1AXWpV8/s640/pins+3+-+3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;What you see from the fifth screen shot above is the actually crimes are not occurring at the traffic junction (intersection) they are occurring just above to the left. Determining this kind of detail wouldn't have been possible if I'd just shown pins or used a low map resolution and a course grained area&amp;nbsp;granularity.&lt;br /&gt;&lt;br /&gt;Now I think this is a great way to use the polygons on top of the map control but the use of squares doesn't quite look or feel right - they are too regular. What is required is a more irregular pattern - how about hexagons or triangles!&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-l2tOXrZ58T0/Ts12xLtQaxI/AAAAAAAAAU8/hVI_y8OgOEY/s1600/pins+3+-+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="588" src="http://4.bp.blogspot.com/-l2tOXrZ58T0/Ts12xLtQaxI/AAAAAAAAAU8/hVI_y8OgOEY/s640/pins+3+-+4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I really like the hexagons, it reminds me of honeycomb...&lt;br /&gt;&lt;br /&gt;Before I get into the code and how it is structured I want to show how this data can be interpreted to generate heat map instead of using pins all together:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-0DfMs7cpC2Y/Ts2Pkmsip-I/AAAAAAAAAVE/UKMURJGYjL4/s1600/pins+3+-+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="398" src="http://1.bp.blogspot.com/-0DfMs7cpC2Y/Ts2Pkmsip-I/AAAAAAAAAVE/UKMURJGYjL4/s640/pins+3+-+5.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I get a similar affect using hexagon shapes:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-BwmcyPCguOI/Ts2UAIzIiAI/AAAAAAAAAVM/j9dSk1Vwgfo/s1600/pins+3+-+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="398" src="http://3.bp.blogspot.com/-BwmcyPCguOI/Ts2UAIzIiAI/AAAAAAAAAVM/j9dSk1Vwgfo/s640/pins+3+-+4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Looking at the code to generate the heat map first this was achieved by binding the crime counts for an area to the Fill property of the&amp;nbsp;MapPolygon class. This is more difficult than it appears and the reason being the Fill property is not a&amp;nbsp;dependency&amp;nbsp;property so you can't bind to it. To get round this I derived from the&amp;nbsp;MapPolygon class and made Fill a dependency property:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;sealed&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; MapPolygonExtended &lt;span style="color: #808030;"&gt;:&lt;/span&gt; MapPolygon&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; DependencyProperty FillProperty &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DependencyProperty&lt;span style="color: #808030;"&gt;.&lt;/span&gt;RegisterAttached&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Fill&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                                                                                 &lt;span style="color: maroon; font-weight: bold;"&gt;typeof&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Brush&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;br /&gt;                                                                                                 &lt;span style="color: maroon; font-weight: bold;"&gt;typeof&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;MapPolygonExtended&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;br /&gt;                                                                                                 &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; PropertyMetadata&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; PropertyChangedCallback&lt;span style="color: #808030;"&gt;(&lt;/span&gt;FillChangedCallback&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; Brush Fill&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        get &lt;span style="color: purple;"&gt;{&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;base&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Fill&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;        set &lt;span style="color: purple;"&gt;{&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;base&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Fill &lt;span style="color: #808030;"&gt;=&lt;/span&gt; value&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; FillChangedCallback&lt;span style="color: #808030;"&gt;(&lt;/span&gt;DependencyObject d&lt;span style="color: #808030;"&gt;,&lt;/span&gt; DependencyPropertyChangedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var dlb &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;MapPolygonExtended&lt;span style="color: #808030;"&gt;)&lt;/span&gt;d&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        dlb&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Fill &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;Brush&lt;span style="color: #808030;"&gt;)&lt;/span&gt;e&lt;span style="color: #808030;"&gt;.&lt;/span&gt;NewValue&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then using this class I'm able to bind a property from the ViewModel to the Fill property:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-iCmuouSOFdE/Ts2c1hZPQSI/AAAAAAAAAVU/lZ4A9k5_zHc/s1600/pins+3+-+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-iCmuouSOFdE/Ts2c1hZPQSI/AAAAAAAAAVU/lZ4A9k5_zHc/s1600/pins+3+-+5.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As you can see from the XAML above I'm using a converter to convert the CrimeCount property from the CrimeShape Model to a solid brush colour. This is where the thresholds are defined for the polygon fill colour:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;sealed&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; CrimeCountConverter &lt;span style="color: #808030;"&gt;:&lt;/span&gt; IValueConverter&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; Convert&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; value&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Type targetType&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; parameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; CultureInfo culture&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var count &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;value&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;count &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; SolidColorBrush&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Colors&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Green&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;count &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;10&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; SolidColorBrush&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Colors&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Orange&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; SolidColorBrush&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Colors&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Red&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; ConvertBack&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; value&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Type targetType&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; parameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; CultureInfo culture&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; NotImplementedException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The CrimeShape Model aggregates the Polygon Model and is bound via the MapViewModel class. These are standard bindable Model &amp;amp; ViewModel classes. I'm not going to show the complete code for these classes, what is shown below is how the top level service is used to generate &amp;amp; group the crime data for rendering onto the map control. Whether the crime data is shown using a heat map or aggregated push pin is not defined in the ViewModel this is defined as shown above in the XAML.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; BuildCrimeMap&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;ukCrimeMapSubscriber &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;MapViewModel: Shutting down existing crime map subscriber...&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        ukCrimeMapSubscriber&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Dispose&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        ukCrimeMapSubscriber &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;MapViewModel: Building crime map...&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;shapeSelected&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        crimeShapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Clear&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;else&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var nonVisible &lt;span style="color: #808030;"&gt;=&lt;/span&gt; crimeShapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Where&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cs &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #808030;"&gt;!&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Intersects&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        nonVisible&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ForEach&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cs &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; crimeShapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Remove&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cs&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    Busy &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    shapeSelected &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;LocationRect&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;r&lt;span style="color: #808030;"&gt;,&lt;/span&gt; s&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Empty&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Name&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ToLower&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Contains&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;square&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;r&lt;span style="color: #808030;"&gt;,&lt;/span&gt; s&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; ukCrimeMapService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TessellateSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;else&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Name&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ToLower&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Contains&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;hexagon&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;r&lt;span style="color: #808030;"&gt;,&lt;/span&gt; s&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; ukCrimeMapService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TessellateHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;else&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Name&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ToLower&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Contains&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;triangle&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;r&lt;span style="color: #808030;"&gt;,&lt;/span&gt; s&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; ukCrimeMapService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TessellateTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    ukCrimeMapSubscriber &lt;span style="color: #808030;"&gt;=&lt;/span&gt; func&lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Any&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cs &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; cs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; crimeShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                crimeShapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShape&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;            exception &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: purple;"&gt;{&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                Busy &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;MapViewModel: Crime shapes count = &lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; crimeShapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see I'm using Rx (Reactive Extensions) again to deal with&amp;nbsp;asynchronous&amp;nbsp;nature of the tessellating function, not only is the method&amp;nbsp;asynchronous&amp;nbsp;it will return a stream of CrimeShape class instances, the number of theses is determined from the input parameters to the tessellating method. I really like the compact nature of the call to the Rx method - from the ViewModel perspective it is only 10 lines of code!&lt;br /&gt;&lt;br /&gt;The service definition is shown below, as you can see I've tried to keep this simple and very clean:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;interface&lt;/span&gt; IUkCrimeMapService&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This service interface is implemented by the UkCrimeMapService class. The responiblity of this class is two-fold:&lt;br /&gt;&lt;br /&gt;Firstly the&amp;nbsp;orchestration&amp;nbsp;of calls to two other services that actually do the work of generating (tessellating) the polygons - ICreatePolygons, and the work to retrieve the crime data from the UK Police back end services - IUKCrimeService.&lt;br /&gt;&lt;br /&gt;Secondly the assignment of polygons and crime data to correct CrimeShape class instance.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;sealed&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; UkCrimeMapService &lt;span style="color: #808030;"&gt;:&lt;/span&gt; IUkCrimeMapService&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; ICreatePolygons polygonService&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; IUkCrimeService crimeService&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; ICacheProvider cacheProvider&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; ILog log&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; TimeSpan cacheTimeout&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; UkCrimeMapService&lt;span style="color: #808030;"&gt;(&lt;/span&gt;ICreatePolygons polygonService&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IUkCrimeService crimeService&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ICacheProvider cacheProvider&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ISettings settings&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ILog log&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygonService &lt;span style="color: #808030;"&gt;=&lt;/span&gt; polygonService&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeService &lt;span style="color: #808030;"&gt;=&lt;/span&gt; crimeService&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;cacheProvider &lt;span style="color: #808030;"&gt;=&lt;/span&gt; cacheProvider&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log &lt;span style="color: #808030;"&gt;=&lt;/span&gt; log&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        cacheTimeout &lt;span style="color: #808030;"&gt;=&lt;/span&gt; TimeSpan&lt;span style="color: #808030;"&gt;.&lt;/span&gt;FromMilliseconds&lt;span style="color: #808030;"&gt;(&lt;/span&gt;settings&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CacheTimeout&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The polygon generating service interface, ICreatePolygons, is defined as follows, I've removed several other mehtods to show only the relevant methods for this post. As you can see this has a similiar structure to the previous service interface:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;interface&lt;/span&gt; ICreatePolygons&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateVisibleSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateVisibleHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateVisibleTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The crime service also has a simply definition, the criterion takes a geo-location for the area you want retrieve crime data for, the data is returned in a one mile radius of the location:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;interface&lt;/span&gt; IUkCrimeService&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;StreetLevelCrimeResult&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; SearchStreetLevelCrime&lt;span style="color: #808030;"&gt;(&lt;/span&gt;StreetLevelCrimeCriterion criterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The way the call to the UkCrimeMapService&amp;nbsp;orchestrates the calls to these services is as follows:&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;/div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;The polygons service is called to tessellate polygons for the required bounding rectangle asynchronously,&lt;/li&gt;&lt;li&gt;As each polygon is received a&amp;nbsp;CrimeShape class instance is created and published,&amp;nbsp;&lt;/li&gt;&lt;li&gt;The number of calls required to retrieve all crimes for the polygon area is calculated,&lt;/li&gt;&lt;li&gt;This list and polygon are then pushed onto a queue to be processed by a background worker,&lt;/li&gt;&lt;li&gt;The background worker starts processing the queue and retrieve the crime data from the UK crime service,&lt;/li&gt;&lt;li&gt;Once all the data is returned the Rx observer is&amp;nbsp;signalled&amp;nbsp;as being complete and the background worker shut down.&lt;/li&gt;&lt;/ol&gt;We use caching where applicable in the services to avoid&amp;nbsp;repetitively&amp;nbsp;creating the same polygons or requesting the same crime data from the UK Police API.&lt;br /&gt;&lt;br /&gt;Steps 1, 2, 3 &amp;amp; 4 are represented by the following two methods:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellatingImpl&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;LocationRect&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; tessellatingFunc&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; polygonName&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var crimeWorker &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CrimeWorker&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var localWorker &lt;span style="color: #808030;"&gt;=&lt;/span&gt; crimeWorker&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Create&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;obs &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        localWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SetObserver&lt;span style="color: #808030;"&gt;(&lt;/span&gt;obs&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        localWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Worker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;DoWork &lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; DoCrimeWork&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        localWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Worker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;WorkerSupportsCancellation &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        localWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Worker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;RunWorkerAsync&lt;span style="color: #808030;"&gt;(&lt;/span&gt;localWorker&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        Scheduler&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ThreadPool&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Schedule&lt;span style="color: #808030;"&gt;(&lt;/span&gt;mapThrottle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; o &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            localWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TessellatingDisposable &lt;span style="color: #808030;"&gt;=&lt;/span&gt; tessellatingFunc&lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #808030;"&gt;.&lt;/span&gt;SubscribeOn&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Scheduler&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ThreadPool&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOn&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Scheduler&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ThreadPool&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; ProcessResponse&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; polygonName&lt;span style="color: #808030;"&gt;,&lt;/span&gt; localWorker&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                            FailedTessellatingPolygons&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; CompletedTessellatingPolygons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;localWorker&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            mapThrottle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; TimeSpan&lt;span style="color: #808030;"&gt;.&lt;/span&gt;FromMilliseconds&lt;span style="color: #808030;"&gt;(&lt;/span&gt;MapSubsequentThrottle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; localWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Disposable&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Finally&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;UkCrimeMapService: Shutting down background worker...&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        crimeWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Dispose&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;UkCrimeMapService: Background worker shutdown...&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; ProcessResponse&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Polygon polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; polygonName&lt;span style="color: #808030;"&gt;,&lt;/span&gt; CrimeWorker crimeWorker&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var cacheKey &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CrimePolygonTuple&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var crimeShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt; cacheProvider&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Get&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;CrimePolygonTuple&lt;span style="color: #808030;"&gt;,&lt;/span&gt; CrimeShape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cacheKey&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var criteria &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Enumerable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Empty&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;StreetLevelCrimeCriterion&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        crimeShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CrimeShape&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; polygonName&lt;span style="color: #808030;"&gt;,&lt;/span&gt; polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        cacheProvider&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cacheKey&lt;span style="color: #808030;"&gt;,&lt;/span&gt; crimeShape&lt;span style="color: #808030;"&gt;,&lt;/span&gt; cacheTimeout&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        criteria &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateCrimeCriteria&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;else&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;!&lt;/span&gt;crimeShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsComplete&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        criteria &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateCrimeCriteria&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsDisposed&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    criteria&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ForEach&lt;span style="color: #808030;"&gt;(&lt;/span&gt;c &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; crimeWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;PushQueue&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CrimeCriterionTuple &lt;span style="color: purple;"&gt;{&lt;/span&gt; CrimeShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt; crimeShape&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Criterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; c &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var observer &lt;span style="color: #808030;"&gt;=&lt;/span&gt; crimeWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Observer&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;observer &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        crimeWorker&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Observer&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnNext&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crimeShape&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Could this code be used in a real world WP7 app?&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;The simple answer is NO!&lt;br /&gt;&lt;br /&gt;The reason for this is not the quality of the code per-se but the fact it's using services that aren't well designed for this use. The code has all the required exception handlers, it also avoid doing work on the UI thread (Dispatcher) as much as possible and it manages the life time of the background worker correctly.&amp;nbsp;What I mean by '&lt;i&gt;services that aren't well designed for this use&lt;/i&gt;'&amp;nbsp;can be best&amp;nbsp;demonstrated&amp;nbsp;by the following three screen shots. The first shows the application running through the WP7 emulator and as we all know the emulator is a really bad place to measure app performance:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-0yr-yBwXepY/Ts5KyfOfr2I/AAAAAAAAAVc/hWPmXTcOnss/s1600/pins+3+-+6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="360" src="http://2.bp.blogspot.com/-0yr-yBwXepY/Ts5KyfOfr2I/AAAAAAAAAVc/hWPmXTcOnss/s640/pins+3+-+6.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As you can see from the highlighted output window in visual studio the total time to create the polygons, retrieve the data from the UK police API backend services and render the heat map is less than &lt;b&gt;8 seconds!&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You start thinking this is looking really promising and then you try it on a device. I tried this on my new Nokia Lumia 800:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Kc5RvtTOAN0/Ts5MXoIKavI/AAAAAAAAAVk/bA-ZxMK18z8/s1600/pins+3+-+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="360" src="http://1.bp.blogspot.com/-Kc5RvtTOAN0/Ts5MXoIKavI/AAAAAAAAAVk/bA-ZxMK18z8/s640/pins+3+-+7.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The elapsed time has risen to &lt;b&gt;14 seconds&lt;/b&gt;, now you're probably thinking this isn't to bad either but what you have to remember is the device is tethered to a machine so the network type is ethernet and importantly I'm only request crime data for a small area.&lt;br /&gt;&lt;br /&gt;When you start to look at a larger area it will increase the elapsed time greatly:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-nrtKGfcPD_M/Ts5Q885Pd4I/AAAAAAAAAVs/oAwQbE4ZDDU/s1600/pins+3+-+8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="390" src="http://2.bp.blogspot.com/-nrtKGfcPD_M/Ts5Q885Pd4I/AAAAAAAAAVs/oAwQbE4ZDDU/s640/pins+3+-+8.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The screen shot above represents an area approximate to 3x2 miles and the time taken is over &lt;b&gt;6 minutes&lt;/b&gt;!&lt;br /&gt;&lt;br /&gt;The majority of the time is consumed in retrieving the crime data, deserializing to JSON and mapping into model classes ready for use. If the UK Crime API&amp;nbsp;was more mature then maybe there would be a better and more&amp;nbsp;simpler&amp;nbsp;way to retrieve this data - &lt;i&gt;I'm going to talk about back end service design in a future post&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;I've made the code available for download via SkyDrive, if you want to run the demo you'll need to register for an account with the UK Police API &lt;a href="http://www.police.uk/api/docs/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The code makes extensive use of the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt; for help with accessing the backend HTTP services, caching of data in memory and the binding of Model classes to the UI.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/Blog%20Posts/HowManyPins3.zip?cid=8503dda7ad75860b&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-4645452168238422234?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/4645452168238422234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/how-many-pins-can-bing-maps-handle-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/4645452168238422234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/4645452168238422234'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/how-many-pins-can-bing-maps-handle-in.html' title='How many pins can Bing Maps handle in a WP7 app - part 3'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-bnRM7u6q4j8/Ts1keInFZ2I/AAAAAAAAAUk/9GHyDsrf_ys/s72-c/pins+3+-+1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-7695283663319277951</id><published>2011-11-21T08:38:00.001-08:00</published><updated>2011-11-21T10:45:05.399-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RavenDB IIS 7.5 Development'/><title type='text'>Setting up RavenDB in IIS 7.5</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I started exploring RavenDB today and the first part was to get an instance running under IIS, specifically running under IIS 7.5 (Windows 7). This is a quick post to help explain a very simple issue I had because of my lack of&amp;nbsp;familiarity&amp;nbsp;with IIS 7.5.&lt;br /&gt;&lt;br /&gt;I downloaded the latest &lt;a href="http://builds.hibernatingrhinos.com/builds/ravendb"&gt;binaries&lt;/a&gt;&amp;nbsp;and followed the&amp;nbsp;instructions for setting up RavenDB can be found &lt;a href="http://ravendb.net/documentation/docs-deployment-iis"&gt;here&lt;/a&gt;. This was very quick and simple, I thought I had everything working, but then I started seeing the following:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-CnVdel7ibjs/TsqIeWqAs1I/AAAAAAAAAUE/mN70QkICD_8/s1600/raven+db+1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-CnVdel7ibjs/TsqIeWqAs1I/AAAAAAAAAUE/mN70QkICD_8/s1600/raven+db+1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;I know RavenDB is being loaded into the IIS Worker Process - because I can see 'Raven' in the error message. Apart from that '&lt;i&gt;Your request didn't match anything that Raven knows to do, sorry...&lt;/i&gt;' didn't really help point me in any useful direction. I can't even tell if the problem is related to RavenDB or IIS 7.5.&lt;br /&gt;&lt;br /&gt;It turns out the problem was related to the ACL for the website configured in IIS 7.5. Specifically I hadn't associated the Application Pool Identity with the website. This &lt;a href="http://learn.iis.net/page.aspx/624/application-pool-identities/"&gt;link&lt;/a&gt; has all the background and information required to complete this association, below is the screenshot for creating the 'RavenDB' app pool association:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-WkxiK372iCk/TsqbrqB0fuI/AAAAAAAAAUU/IoDrAwRLZzk/s1600/raven+db+2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-WkxiK372iCk/TsqbrqB0fuI/AAAAAAAAAUU/IoDrAwRLZzk/s1600/raven+db+2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Once this was done I was able to run management studio and create the default database and actually start some work :)&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-IZy5RGFr98U/Tsqb3Es--DI/AAAAAAAAAUc/xhISIiiynFE/s1600/raven+db+3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-IZy5RGFr98U/Tsqb3Es--DI/AAAAAAAAAUc/xhISIiiynFE/s1600/raven+db+3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-7695283663319277951?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/7695283663319277951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/setting-up-ravendb-in-iis-75.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7695283663319277951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7695283663319277951'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/setting-up-ravendb-in-iis-75.html' title='Setting up RavenDB in IIS 7.5'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-CnVdel7ibjs/TsqIeWqAs1I/AAAAAAAAAUE/mN70QkICD_8/s72-c/raven+db+1.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-990388081282162018</id><published>2011-11-04T10:50:00.000-07:00</published><updated>2011-11-04T13:15:47.426-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FindaPad Property Rental Windows Phone 7 Mobile Devices'/><title type='text'>Please welcome FINDaPAD to the WP7 app store</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I'm proud to announce the release of &lt;a href="http://findapad.biz/"&gt;FINDaPAD&lt;/a&gt; into the WP7 &lt;a href="http://www.windowsphone.com/en-GB/apps/2d496451-8fd3-426f-b4dd-3d323781931d"&gt;app store&lt;/a&gt;, it's been a long journey&amp;nbsp;working&amp;nbsp;on this app and I'd like to thank my co-workers &lt;a href="http://twitter.com/#!/RichGee"&gt;Rich&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="http://twitter.com/#!/spacescape"&gt;Nick&lt;/a&gt;&amp;nbsp;for all their hard work. We've spent the last 6 months working on this at the weekends and as with all software released to market the last few weeks seem to have been the hardest.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;So what is a FINDaPAD?&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;FINDaPAD is a property search app for buy or rental properties in the UK housing market.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We aren't the first app to go to market offer property search services but we do believe we offer something different from a UI perspective - we've tried to follow the Metro-style guidelines for WP7 as much as possible. The app is very much designed with the idea of being used when you're&amp;nbsp;&lt;i&gt;out &amp;amp; about&lt;/i&gt; looking for properties and you need a quick and easy way to search the local area. You also have the ability to search locations using post code, place name or geo-location.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The rest of this post describes the technologies used in developing the app.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The app is currently &lt;b&gt;NOT &lt;/b&gt;a mango app - yes I've said it, it's &lt;b&gt;NOT&lt;/b&gt; a&amp;nbsp;mango&amp;nbsp;app. The simple reason being we started the app on the 7.0 and we took the decision in late August not to move to Mango&amp;nbsp;until&amp;nbsp;after we had a stable release. August might seem a long time ago but when you're trying to get something out of the door, days and weeks seem to go by very quickly indeed. The app was first submitted for approval prior to the Microsoft BUILD conference in early September and after two failed submissions it was finally approved and in the store by late September.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You might be wondering why wait until now to start talking and&amp;nbsp;publicising&amp;nbsp;the app?&amp;nbsp;We realised after getting the app into the market place there was still plenty to do - &lt;a href="http://findapad.biz/"&gt;website&lt;/a&gt;, &lt;a href="http://twitter.com/#!/FindAPad"&gt;twitter&lt;/a&gt;,&amp;nbsp;PR, support, etc. We choose the achievement of a successful submission to be a &lt;i&gt;soft&lt;/i&gt;&amp;nbsp;launch of the app with friends and relatives testing and giving feedback. Since the initial release we've submitted eight updates to the market place in the last 6 weeks, these including a couple of big bug fixes and the addition of missing functionality which only became obvious after family used it to find their new home in Brighton. So now we're ready for a &lt;i&gt;hard&lt;/i&gt;&amp;nbsp;release with a PR push.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We built the app using the following APIs, frameworks &amp;amp; libraries:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.nestoria.co.uk/help/api"&gt;Nestoria API&lt;/a&gt; - &lt;i&gt;open source API providing property information for the UK and other countries&lt;/i&gt;,&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.police.uk/api/docs/"&gt;UK Crime API&lt;/a&gt; - &lt;i&gt;open source API providing crime stats for the UK&lt;/i&gt;,&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt;&lt;i&gt; - we use this for all communication with back end web services, custom MVVMLight messenger, UI transitions and custom controls including SmartTextBlock,&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://silverlight.codeplex.com/"&gt;Silverlight Toolkit&lt;/a&gt;&lt;i&gt; - LongListSelector for infinite scrolling lists and bing maps control,&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://mvvmlight.codeplex.com/"&gt;MVVMLight Toolkit&lt;/a&gt; - &lt;i&gt;Laurent's great framework for making life with MVVM easier,&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://msdn.microsoft.com/en-us/devlabs/gg577609"&gt;Reactive Extensions (Rx)&lt;/a&gt;&lt;i&gt; - we use this for handling asynchronous calls and event subscriptions,&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.visiblox.com/"&gt;Visiblox &lt;/a&gt;- a&lt;i&gt;&amp;nbsp;great charting package for visualising data, big thanks to&amp;nbsp;&lt;a href="http://twitter.com/#!/ColinEberhardt"&gt;@ColinEberhardt&lt;/a&gt;&lt;/i&gt;,&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://funq.codeplex.com/"&gt;Funq&lt;/a&gt;&lt;i&gt;- a compact and fast DI container for WP7,&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://wp7.runtimeintelligence.com/"&gt;PreEmptive Solutions&lt;/a&gt; - &lt;i&gt;post build weaving of runtime analytics into executables.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;We're now working on a Mango release and hope to have this out in a couple of weeks and we're looking forward to performance improvements around HTTP compression support and fast app switching.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Until then&amp;nbsp;happy property searching :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-OWDW1GCXsXU/TrQlj8rv9gI/AAAAAAAAATs/c92CcfabHnA/s1600/fb+screenshots.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-OWDW1GCXsXU/TrQlj8rv9gI/AAAAAAAAATs/c92CcfabHnA/s1600/fb+screenshots.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-990388081282162018?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/990388081282162018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/please-welcome-findapad-to-wp7-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/990388081282162018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/990388081282162018'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/please-welcome-findapad-to-wp7-app.html' title='Please welcome FINDaPAD to the WP7 app store'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-OWDW1GCXsXU/TrQlj8rv9gI/AAAAAAAAATs/c92CcfabHnA/s72-c/fb+screenshots.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-5119462728905286253</id><published>2011-11-03T15:47:00.000-07:00</published><updated>2011-11-03T15:51:59.506-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 Bing Maps Development UK Polygons Clustering Performance'/><title type='text'>Tessellating shapes on top of Bing Maps in a WP7 app - part 2</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In my previous &lt;a href="http://awkwardcoder.blogspot.com/2011/10/tessellating-shapes-on-top-of-bing-maps.html"&gt;post&lt;/a&gt;&amp;nbsp;I showed how to tessellate polygons over Bing Maps control. This was a&amp;nbsp;demonstration of how to achieving tessellation over the map control for a WP7 app. The problem is this is a sub-optimal solution from a UI perspective.&amp;nbsp;This post shows how I've changed to code to use an asynchronous pattern for creating the polygons. The code is available for download.&lt;br /&gt;&lt;br /&gt;The primary problem with the solution is not the actual calculation but '&lt;i&gt;where&lt;/i&gt;' the calculation was being performed. All the work was done on the main UI (Dispatcher) thread. Simply this means the app would freeze whilst calculating the required the polygons for the currently visible map area.&lt;br /&gt;&lt;br /&gt;The secondary problem&amp;nbsp;was overloading the UI thread with rendering requests. Obviously all the visible polygons need rendering to the screen, but if you chuck a lot of work at the UI thread nothing else in your app is going to be able to do any UI work until all those requests have been processed. This means at best you'll get a jerk response or at worst you'll app will freeze.&lt;br /&gt;&lt;br /&gt;And finally there isn't any caching for already calculated polygons for a geo-location, why would we want to repeat the same work over and over again.&lt;br /&gt;&lt;br /&gt;The first approach to address these issues is the introduction of a service interface exposing the polygon methods asynchronously:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;interface&lt;/span&gt; ICreatePolygons&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    ISettings Settings &lt;span style="color: purple;"&gt;{&lt;/span&gt; get&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    Polygon Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt; sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; offset&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; offsetBearing&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; startAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; AdjacentSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Polygon polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateVisibleSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; existingPolygons&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; AdjacentHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Polygon polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateVisibleHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; visiblePolygons&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Triangle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; AdjacentTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Polygon polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; TessellateVisibleTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; visiblePolygons&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see all the methods apart from the Polygon method all return the polygons using the Rx (Reactive extensions) approach. This allows the actual work of calculating the polygons to be done on a background worker thread and solve the primary problem with the previous solution - freezing of the UI.&lt;br /&gt;&lt;br /&gt;Shown below is the Hexagon method, what you can see is how I schedule the work onto the thread pool using Rx:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;try&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ValidateDatum&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Create&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;obs &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            var disposable &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; BooleanDisposable&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            Scheduler&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ThreadPool&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Schedule&lt;span style="color: #808030;"&gt;(&lt;/span&gt;o &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                var polygon &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CreateHexagonImpl&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; size&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;disposable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsDisposed&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                obs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnNext&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                obs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnCompleted&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; disposable&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;Exception exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;FailedHexagon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ServiceException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;FailedHexagon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The secondary problem is solved easily with the primary change in place. The addition of a pause to the thread calculating the adjacent &amp;nbsp;polygons when tessellating the polygons for the map control.&lt;br /&gt;&lt;br /&gt;Shown below is the recursive method used to calculate the visible adjacent polygons, what you'll see is the 'Thread.SpinWait' added every time an adjacent polygon is found and notified to any subscribers of the observer. This allows the background thread to cease work for a fixed amount of time (default is 66 ms) without causing a context switch. I found using a delay of 66 ms was enough to allow other threads\controls enough time to do their stuff, in my case this was allow the map control to render &amp;amp; download tiles and allow the use&amp;nbsp;interact&amp;nbsp;with the UI.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; AddVisibleAdjacentPolygons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                        Polygon polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ICollection&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; newPolygons&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                        Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; adjacentPolygonFunc&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                        IObserver&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; observer&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                        BooleanDisposable disposable&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;foreach&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var adjacentPolygon &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; adjacentPolygonFunc&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;disposable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsDisposed&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;!&lt;/span&gt;visibleRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Intersects&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;newPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Contains&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        newPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        observer&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnNext&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        Thread&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SpinWait&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;settings&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Throttle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AddVisibleAdjacentPolygons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;visibleRectangle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; adjacentPolygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; newPolygons&lt;span style="color: #808030;"&gt;,&lt;/span&gt; adjacentPolygonFunc&lt;span style="color: #808030;"&gt;,&lt;/span&gt; observer&lt;span style="color: #808030;"&gt;,&lt;/span&gt; disposable&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The final problem is address by a standard pattern - caching. For this I'm using the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt; caching assembly. Before I show how I use the cache provider lets look at the generation times for different polygon tessellations.&lt;br /&gt;&lt;br /&gt;Shown below is with no caching for the initial tessellation generation for 1 mile squares (on a device not in the emulator). As you can see the duration is 8247 ms:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-CMigpk8kpRo/TrMQsHuc1zI/AAAAAAAAAS8/2nvGT3S57dI/s1600/tess+caching+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-CMigpk8kpRo/TrMQsHuc1zI/AAAAAAAAAS8/2nvGT3S57dI/s1600/tess+caching+1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;When I move the map around in the local&amp;nbsp;vicinity you can see the durations are about half of the start-up time when caching is not enabled:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-6IQdDiE5B2s/TrMRXTrR6wI/AAAAAAAAATE/dg6xLkIim-c/s1600/tess+caching+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-6IQdDiE5B2s/TrMRXTrR6wI/AAAAAAAAATE/dg6xLkIim-c/s1600/tess+caching+2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;When caching for adjacent polygons is enabled we get similar result for the initial start-up:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-pQut11wmr04/TrMVCv-KLMI/AAAAAAAAATU/-mvoRqnBak4/s1600/tess+caching+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-pQut11wmr04/TrMVCv-KLMI/AAAAAAAAATU/-mvoRqnBak4/s1600/tess+caching+3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;But when you compare the subsequent requests for the local&amp;nbsp;vicinity&amp;nbsp;you can see the time for generating the adjacent polygons has been reduced:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-fJv9bTTcxYQ/TrMVjKbh8vI/AAAAAAAAATc/EyBRvB_hgVM/s1600/tess+caching+4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-fJv9bTTcxYQ/TrMVjKbh8vI/AAAAAAAAATc/EyBRvB_hgVM/s1600/tess+caching+4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This demo makes use of the WP7Contrib in memory cache provider.&amp;nbsp;The code for this demo app is available on SkyDrive.&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/Blog%20Posts/TessellationDemo2.zip?cid=8503dda7ad75860b&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-5119462728905286253?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/5119462728905286253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/tessellating-shapes-on-top-of-bing-maps.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/5119462728905286253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/5119462728905286253'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/11/tessellating-shapes-on-top-of-bing-maps.html' title='Tessellating shapes on top of Bing Maps in a WP7 app - part 2'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-CMigpk8kpRo/TrMQsHuc1zI/AAAAAAAAAS8/2nvGT3S57dI/s72-c/tess+caching+1.png' height='72' width='72'/><thr:total>0</thr:total><georss:featurename>9-67 Beatty Rd, Hackney, Greater London N16 8, UK</georss:featurename><georss:point>51.55655550350541 -0.0764322280883789</georss:point><georss:box>51.55408750350541 -0.0813677280883789 51.55902350350541 -0.07149672808837891</georss:box></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-7033453661168651742</id><published>2011-10-28T09:37:00.000-07:00</published><updated>2011-11-04T13:14:53.620-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 Bing Maps Development UK Polygons Clustering Performance'/><title type='text'>Tessellating shapes on top of Bing Maps in a WP7 app</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div&gt;Before I complete the '&lt;i&gt;How many pins can Bing Maps handle in a WP7 app...&lt;/i&gt;' set of &lt;a href="http://awkwardcoder.blogspot.com/2011/09/how-many-pins-can-bing-maps-handle-in.html"&gt;posts&lt;/a&gt;. I want to take one last diversion and show how you can tessellate shapes on top of the Bing Maps control in a WP7 app. This builds on top of a previous &lt;a href="http://awkwardcoder.blogspot.com/2011/10/drawing-shapes-on-top-of-bing-maps-in.html"&gt;post &lt;/a&gt;about drawing shapes on top of Bing Maps.&amp;nbsp;If you're unsure what tessellation is, then the following definition should give you a good idea:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;A tessellation is created when a shape is repeated over and over again covering a plane without any gaps or overlaps.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="background-color: white; font-style: normal;"&gt;Only three regular polygons tessellate in the Euclidean plane: triangles, squares or hexagons. Shown below are some graphical examples of how these shapes tessellate:&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="background-color: white; font-style: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ML-soQjfT3I/Tqp4XDpYl6I/AAAAAAAAAOQ/DpRxFja2fm4/s1600/tess+shapes.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-ML-soQjfT3I/Tqp4XDpYl6I/AAAAAAAAAOQ/DpRxFja2fm4/s1600/tess+shapes.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;I'm only going to show how you can tessellate these shapes on top of the map control. The effect will be rendered as a set of MapPolygon class instances. You could achieve a similar effect with a set of MapPolyline class instances and it would be probably a lot easier but, and it is an important 'but', if you use a MapPolyline you won't be able to use the polygon colour fill functionality. The MapPolygon instances are render as a layer&amp;nbsp;on top&amp;nbsp;of the map control, the control provides this functionality out of the box, this means the XAML is very clean and easy to understand:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-jSJLbX7NJbc/Tqp849A8fyI/AAAAAAAAAOY/o25zf8W51uM/s1600/tess+xaml+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-jSJLbX7NJbc/Tqp849A8fyI/AAAAAAAAAOY/o25zf8W51uM/s1600/tess+xaml+1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;As you can see the polygons are rendered as part of the MapItemsControl instance, the item source is bound to the Polygons property on the ViewModel. The item template is shown below and you can see this is also very simple. I've also included the brush definitions so you can see where the polygon colours are defined:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Ub2aF3r_Y2c/Tqp-Egw-HxI/AAAAAAAAAOg/Kzpjrg8-o3A/s1600/tess+xaml+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-Ub2aF3r_Y2c/Tqp-Egw-HxI/AAAAAAAAAOg/Kzpjrg8-o3A/s1600/tess+xaml+2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Before I dive into the code used to generate the polygons lets see the effect I'm going to generate, shown below are a set of tessellated shapes at different sizes. The density of polygons on the screen is dependent on the zoom level of the map control - here I'm using a default zoom level of 13 when the app starts, obviously you can zoom in and out as required and the polygons will automatically re size. This functionality is provided by the parent MapLayer class instance.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-4GJ3w6ZaAbU/TqqGwrLNLtI/AAAAAAAAAOo/SIIYRVxCaR0/s1600/tess+-+examples.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-4GJ3w6ZaAbU/TqqGwrLNLtI/AAAAAAAAAOo/SIIYRVxCaR0/s640/tess+-+examples.png" width="576" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Here I'm using a set of pre-defined shapes, these are defined in the ViewModel constructor which is shown below. You can see each Shape class instance has a Name property and 2&amp;nbsp;function delegate properties -&amp;nbsp;PolygonFunc and&amp;nbsp;AdjacentPolygonFunc. This is the same style I used in the previous &lt;a href="http://awkwardcoder.blogspot.com/2011/10/drawing-shapes-on-top-of-bing-maps-in.html"&gt;post&lt;/a&gt;.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; MapViewModel&lt;span style="color: #808030;"&gt;(&lt;/span&gt;ILog log&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log &lt;span style="color: #808030;"&gt;=&lt;/span&gt; log&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygons &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ObservableCollection&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;datum &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;51.54590803376571&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt;&lt;span style="color: green;"&gt;0.10334014892578125&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;51.561811605968394&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt;&lt;span style="color: green;"&gt;0.0883626937866211&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Zoom &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;13&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;shapes &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ObservableCollection&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Shape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;No Shape&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (100 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;100&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;100&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (200 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;200&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;200&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (500 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (1 km)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (1 mile)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;1609.347&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentSquares&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;1609.347&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Triangle (3 sides, 500 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Triangle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Triangle (3 sides, 1 km)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Triangle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Triangle (3 sides, 1 mile)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Triangle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;1609.347&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentTriangles&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;1609.347&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Hexagon (6 sides, 500 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Hexagon (6 sides, 1 km)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Hexagon (6 sides, 1 mile)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;1609.347&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; AdjacentPolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;1609.347&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SelectedShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;shapes&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;Hopefully the delegate method names are obvious, PolygonFunc calculates the geo-location points for the shape and the AdjacentPolygonFunc. The shapes are divided into 2 distinct groupings - squares and everything else. Squares are easy to calculate because you only have to calculate geo-locations for 4 points using constant bearings &amp;nbsp;- 0, 90, 180 &amp;amp; 270. Everything else is where it starts to get complicated, you have to use a circle and calculate the position of each point on the&amp;nbsp;circumference. The diameter for the circle comes from the defined size of the shape.&lt;br /&gt;&lt;br /&gt;Shown below is the&amp;nbsp;PolygonFunc method for creating a hexagon, as you can see the hexagon is generated using the Polygon method we also set the Height &amp;amp; Width of the generated polygon.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; location &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var hexagon &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;6&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var north &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var south &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var east &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var west &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;              &lt;br /&gt;        hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Height &lt;span style="color: #808030;"&gt;=&lt;/span&gt; north&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetDistanceTo&lt;span style="color: #808030;"&gt;(&lt;/span&gt;south&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Width &lt;span style="color: #808030;"&gt;=&lt;/span&gt; east&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetDistanceTo&lt;span style="color: #808030;"&gt;(&lt;/span&gt;west&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; hexagon&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; func&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The Polygon method is shown below, this is ultimately the same method used to create triangles as well as hexagons:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Polygon Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt; sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; offset&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; offsetBearing&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; startAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; location&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;offset &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; offset&lt;span style="color: #808030;"&gt;,&lt;/span&gt; offsetBearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var polygon &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var radius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; diameter &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var angle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CircleInDegresses &lt;span style="color: #808030;"&gt;/&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var i &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; i &lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt; i&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var aggregatedAngle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;i &lt;span style="color: #808030;"&gt;*&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; startAngle&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centre&lt;span style="color: #808030;"&gt;,&lt;/span&gt; radius&lt;span style="color: #808030;"&gt;,&lt;/span&gt; aggregatedAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; centre&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;diameter&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; polygon&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For this demo I'm using the Haversine method for calculating distance between two geo-locations. There are more accurate ways to calculate geo-locations, I'm aware of the error factor (0.3 %) and happy to negate this for Haversine formula. The reason is simple - in a real-world app I won't be displaying a large number of polygons over a large areas (see the 'square 100 metre' in the above screenshot) so therefore the total distances calculated would not be large and the error factor would be small. Shown below is a screenshot of a single hexagon polygon rendered onto the map control.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Bv2KsJebmrU/TqqWxPlbi1I/AAAAAAAAAOw/ZjIa-ojfKsw/s1600/tess+-+single+hexagon.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/-Bv2KsJebmrU/TqqWxPlbi1I/AAAAAAAAAOw/ZjIa-ojfKsw/s320/tess+-+single+hexagon.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The purpose of the&amp;nbsp;AdjacentPolygonFunc method should be obvious - to calculate the adjacent polygons for an existing polygon. The implementation of this function depends on the type of polygon, the number of adjacent polygons for a square is different to a triangle or hexagon.&amp;nbsp;Shown below are the rendered&amp;nbsp;adjacents; I've added the order in which the adjacent polygons are calculated. An understand of the order of calculation is important when it comes to rendering the rest of the polygons for the visible map control.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-z0iiKV_Xd0s/Tqqbkbq731I/AAAAAAAAAO4/9_dXtFvkTks/s1600/tess+-+adjacents.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="353" src="http://2.bp.blogspot.com/-z0iiKV_Xd0s/Tqqbkbq731I/AAAAAAAAAO4/9_dXtFvkTks/s640/tess+-+adjacents.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As I said the adjacent methods are dependent on the type of polygon and calculating the adjacents for a square is the easiest. Shown below is the method used for adjacent hexagons. It requires not only the ability to calculate the polygon points but the ability to calculate the points in the correct geo-locations - the points have to be '&lt;i&gt;massaged&lt;/i&gt;' into the correction geo-locations.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; AdjacentHexagons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var adjacentPolygons &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        GeoCoordinate deltaNorthWest&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        GeoCoordinate deltaNorthEast&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        GeoCoordinate deltaSouthWest&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        GeoCoordinate deltaSouthEast&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate the horizontal distance between the edge of the hexagon and the edge of the bounding rectangle&lt;/span&gt;&lt;br /&gt;        var eastEdge &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OrderByDescending&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Select&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;First&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                            hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OrderByDescending&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Select&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;First&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var horizontalDelta &lt;span style="color: #808030;"&gt;=&lt;/span&gt; eastEdge&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetDistanceTo&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northeast&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate the vertical distance between the top of the hexagon and the top of the east edge&lt;/span&gt;&lt;br /&gt;        var northEdge1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OrderByDescending&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;First&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var northEdge2 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OrderByDescending&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ThenByDescending&lt;span style="color: #808030;"&gt;(&lt;/span&gt;l &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; l&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;First&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var verticalDelta &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;60.00&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; northEdge1&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetDistanceTo&lt;span style="color: #808030;"&gt;(&lt;/span&gt;northEdge2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate top centre hexagon position....&lt;/span&gt;&lt;br /&gt;        deltaNorthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; verticalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;180&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaNorthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; verticalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;180&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var topCentre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaNorthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        topCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate bottom centre hexagon position....&lt;/span&gt;&lt;br /&gt;        deltaSouthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; verticalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; verticalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var bottomCentre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaSouthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;180&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;180&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        bottomCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate centre right hexagon position...&lt;/span&gt;&lt;br /&gt;        deltaNorthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var centreRight &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        centreRight&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centreRight&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate centre left hexagon position...&lt;/span&gt;&lt;br /&gt;        deltaNorthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hexagon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var centreLeft &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        centreLeft&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centreLeft&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate top right hexagon position...&lt;/span&gt;&lt;br /&gt;        deltaNorthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var topRight &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        topRight&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topRight&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate top left hexagon position...&lt;/span&gt;&lt;br /&gt;        deltaNorthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var topLeft &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        topLeft&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topLeft&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate bottom right hexagon position...&lt;/span&gt;&lt;br /&gt;        deltaNorthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southeast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var bottomRight &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthEast&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        bottomRight&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomRight&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate bottom left hexagon position...&lt;/span&gt;&lt;br /&gt;        deltaNorthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Northwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        deltaSouthWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomCentre&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Southwest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; horizontalDelta &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: green;"&gt;4.225&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var bottomLeft &lt;span style="color: #808030;"&gt;=&lt;/span&gt; AdjacentSquare&lt;span style="color: #808030;"&gt;(&lt;/span&gt;deltaNorthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; deltaSouthWest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        bottomLeft&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Hexagon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomLeft&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        adjacentPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topRight&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        adjacentPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centreRight&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        adjacentPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomRight&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        adjacentPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bottomLeft&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        adjacentPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centreLeft&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        adjacentPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;topLeft&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; adjacentPolygons&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; func&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;So how I do generate all the adjacent polygons for the visible area of the map control?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Simply using one of favourite programming techniques - recursion!&lt;br /&gt;&lt;br /&gt;This is were the order of creating the adjacent polygons becomes important. The pattern follows the&amp;nbsp;principle&amp;nbsp;of always creating the adjacent polygons for the current polygon and then moving to the next adjacent polygon and repeating ad infinitum. There is a break clause for the recursion to prevent an infinite loop - if the current polygon is not visible it does not calculate the adjacent polygons. This means only the visible polygons are calculated for the visible area of the map control.&lt;br /&gt;&lt;br /&gt;Shown below is the visible order the polygons are calculated for all supported shapes, I've shown the first 12 polygons being calculated and rendered.&lt;br /&gt;&lt;br /&gt;The first 12 squares:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-DVWU4A9WSuc/Tqq7JM9Tg5I/AAAAAAAAAPI/M2-6CHmaL3Q/s1600/tess+-+squares+recursion.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="356" src="http://2.bp.blogspot.com/-DVWU4A9WSuc/Tqq7JM9Tg5I/AAAAAAAAAPI/M2-6CHmaL3Q/s640/tess+-+squares+recursion.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The first 12 triangles:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1W5WZPHZnE0/TqrEtzdWwcI/AAAAAAAAAPQ/OGHRRLodYQ0/s1600/tess+-+triangles+recursion.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="358" src="http://4.bp.blogspot.com/-1W5WZPHZnE0/TqrEtzdWwcI/AAAAAAAAAPQ/OGHRRLodYQ0/s640/tess+-+triangles+recursion.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The first 12 hexagons:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-tdRnxD7C5S0/TqrHLiLtUpI/AAAAAAAAAPY/FF_bOtvuYPc/s1600/tess+-+hexagons+recursion.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="358" src="http://3.bp.blogspot.com/-tdRnxD7C5S0/TqrHLiLtUpI/AAAAAAAAAPY/FF_bOtvuYPc/s640/tess+-+hexagons+recursion.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Shown below is the recursive method I use to calculate all the visible adjacent polygons. As you can see this method is short and concise - all the logic for creating the adjacent polygons is abstracted away in the AdjacentPolygonFunc. The only other logic is&amp;nbsp;to work out if an adjacent polygon is visible on the screen, this uses the Intersects method on the bounding rectangle of the map control. To prevent an infinite loop occurring we also check to see if an adjacent polygon has already been created and added to the existing polygons list.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; AddVisibleAdjacentPolygons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Polygon polygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ICollection&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; existingPolygons&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var adjacentPolygons &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;selectedShape&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AdjacentPolygonFunc&lt;span style="color: #808030;"&gt;(&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;foreach&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var adjacentPolygon &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; adjacentPolygons&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Intersects&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TileBoundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;!&lt;/span&gt;existingPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Contains&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            existingPolygons&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AddVisibleAdjacentPolygons&lt;span style="color: #808030;"&gt;(&lt;/span&gt;adjacentPolygon&lt;span style="color: #808030;"&gt;,&lt;/span&gt; existingPolygons&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The only remaining&amp;nbsp;visibility&amp;nbsp;issue is the use of a '&lt;i&gt;datum&lt;/i&gt;' for tessellation. Wikipedia defines a '&lt;i&gt;geodetic datum is a reference from which measurements are made&lt;/i&gt;'.&lt;br /&gt;&lt;br /&gt;In the examples above I'm using '&lt;i&gt;Highbury Corner&lt;/i&gt;' in central London as the datum point for tessellating shapes, this is why the polygons do not start in the centre off the visible bounding rectangle. The idea being where every I scroll the map control to, all the rendered polygons should start from this point.&lt;br /&gt;&lt;br /&gt;Since it's possible I'm not rendering all the polygons between the datum and the centre of the visible bounding rectangle&amp;nbsp;I need to be able to work out the closes point to the centre of the visible bounding rectangle when the datum point is not visible. This is achieved using geometry and&amp;nbsp;Pythagoras&amp;nbsp;theorem.&lt;br /&gt;&lt;br /&gt;I need to be able to work out the shortest hypotenuse between the datum (start) and the centre of the visible bounding rectangle (end). The horizontal and vertical components of this hypotenuses has to be an absolute factor of the height and width of the polygon. Once this value is calculated I then use the Haversine formula to calculate the exact geo-location of the centre polygon.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; GeoCoordinate CalculateClosestPolygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate start&lt;span style="color: #808030;"&gt;,&lt;/span&gt; GeoCoordinate end&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Polygon polygon&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var hypotenuse &lt;span style="color: #808030;"&gt;=&lt;/span&gt; start&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetDistanceTo&lt;span style="color: #808030;"&gt;(&lt;/span&gt;end&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;hypotenuse &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; start&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var bearing &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateBearing&lt;span style="color: #808030;"&gt;(&lt;/span&gt;start&lt;span style="color: #808030;"&gt;,&lt;/span&gt; end&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var absoluteBearing &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Abs&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var vertical &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;absoluteBearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; hypotenuse&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var horizontal &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;absoluteBearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; hypotenuse&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var rectifiedHorizontalLength &lt;span style="color: #808030;"&gt;=&lt;/span&gt; RectifiedLength&lt;span style="color: #808030;"&gt;(&lt;/span&gt;horizontal&lt;span style="color: #808030;"&gt;,&lt;/span&gt; polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Width&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var rectifiedVerticalLength &lt;span style="color: #808030;"&gt;=&lt;/span&gt; RectifiedLength&lt;span style="color: #808030;"&gt;(&lt;/span&gt;vertical&lt;span style="color: #808030;"&gt;,&lt;/span&gt; polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Height&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var rectifiedHypotenuseLength &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sqrt&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;rectifiedHorizontalLength &lt;span style="color: #808030;"&gt;*&lt;/span&gt; rectifiedHorizontalLength&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;rectifiedVerticalLength &lt;span style="color: #808030;"&gt;*&lt;/span&gt; rectifiedVerticalLength&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var closestEnd &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;start&lt;span style="color: #808030;"&gt;,&lt;/span&gt; rectifiedHypotenuseLength&lt;span style="color: #808030;"&gt;,&lt;/span&gt; bearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; closestEnd&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-vJJyFWY5y7M/TqrQfirRL1I/AAAAAAAAAPg/XIRfKoKe8fA/s1600/tess+memory.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="496" src="http://1.bp.blogspot.com/-vJJyFWY5y7M/TqrQfirRL1I/AAAAAAAAAPg/XIRfKoKe8fA/s640/tess+memory.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;The final issue is really an observation about memory consumption - the more polygons I add to the map control the closer I get to the 90 Mb limit. As you can see from the screenshot above I managed to get the peak memory usage over 180 Mb!&amp;nbsp;You can see from the output window in visual studio the reason why the right hand screenshot above peaks at such a high value, the number of visible polygons is over 3700!&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-NYBmV9l9TsE/TqrdhuIO3NI/AAAAAAAAAPo/bbCVt7o1iMM/s1600/tess+output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-NYBmV9l9TsE/TqrdhuIO3NI/AAAAAAAAAPo/bbCVt7o1iMM/s1600/tess+output.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This is another&amp;nbsp;demonstration&amp;nbsp;of the problems you can have with a data set with a large if not infinite size. To get round this issue I would limit the minimum size of the polygons depending on the zoom level of the map control.&lt;br /&gt;&lt;br /&gt;If you've reached this far and are still wondering what's the use of tessellating polygons over the map control?&lt;br /&gt;&lt;br /&gt;The simple answer is to cluster pins or other visual information that has a geo-location value.&amp;nbsp;In the final '&lt;i&gt;How many pins can Bing Maps handle in a WP7 app...' &lt;/i&gt;&amp;nbsp;I will show how you can conflate (cluster) large numbers of map pins for a relatively small visible area.&lt;br /&gt;&lt;br /&gt;The code makes use of the WP7Contrib for the base class for the ViewModel &amp;amp; Model classes and is referenced as an NuGet packages. The code for this demo app is available on SkyDrive.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/Blog%20Posts/TessellationDemo.zip?cid=8503dda7ad75860b&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-7033453661168651742?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/7033453661168651742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/tessellating-shapes-on-top-of-bing-maps.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7033453661168651742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7033453661168651742'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/tessellating-shapes-on-top-of-bing-maps.html' title='Tessellating shapes on top of Bing Maps in a WP7 app'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-ML-soQjfT3I/Tqp4XDpYl6I/AAAAAAAAAOQ/DpRxFja2fm4/s72-c/tess+shapes.png' height='72' width='72'/><thr:total>2</thr:total><georss:featurename>9-67 Beatty Rd, Hackney, Greater London N16 8, UK</georss:featurename><georss:point>51.55658218576253 -0.07784843444824219</georss:point><georss:box>51.55164618576253 -0.08771893444824219 51.56151818576253 -0.06797793444824218</georss:box></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-7235501851343312494</id><published>2011-10-23T14:12:00.000-07:00</published><updated>2011-10-23T14:16:19.197-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7Contrib WP7 HTTP Compression'/><title type='text'>WP7Contrib: Added support for GZip compression to ResourceClient</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;With the release of Mango for WP7 and a user request for GZip compression support in the contrib I've added GZip compression support to the ResourceClient in &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt;.This means you can now request GZip compression for HTTP requests against back end web servers when using the ResourceClient in the contrib. All you have to do is specify 'WithGZip' method in the setup:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-WQTkDBam0Y4/TqR_4XqWdCI/AAAAAAAAAMA/6X8AwiTsSto/s1600/GZip+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-WQTkDBam0Y4/TqR_4XqWdCI/AAAAAAAAAMA/6X8AwiTsSto/s1600/GZip+1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;When you compare the debug statements in the output window of visual studio you can see the difference in HTTP response lengths, the first shows no compression and the second includes compression:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FyOp4tczcEw/TqSA-c_ENqI/AAAAAAAAAMI/s02fCTY7Xqc/s1600/GZip+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-FyOp4tczcEw/TqSA-c_ENqI/AAAAAAAAAMI/s02fCTY7Xqc/s1600/GZip+2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-wVm7IbwdVRk/TqSBdN_IvHI/AAAAAAAAAMQ/imBKA3Qkc9k/s1600/GZip+3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href="http://3.bp.blogspot.com/-wVm7IbwdVRk/TqSBdN_IvHI/AAAAAAAAAMQ/imBKA3Qkc9k/s1600/GZip+3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href="http://3.bp.blogspot.com/-wVm7IbwdVRk/TqSBdN_IvHI/AAAAAAAAAMQ/imBKA3Qkc9k/s1600/GZip+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-wVm7IbwdVRk/TqSBdN_IvHI/AAAAAAAAAMQ/imBKA3Qkc9k/s1600/GZip+3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;As you can see the HTTP response length drops from 43273 (bytes) to 8927 (bytes), this is obviously great not only from a performance point of view of the app but also from the cost to user, we have managed to lower their data usage.&lt;br /&gt;&lt;br /&gt;This code is available in the GZipDemo app in the WP7Contrib Spikes directory (7.1).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-7235501851343312494?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/7235501851343312494/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/wp7contrib-added-support-for-gzip.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7235501851343312494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7235501851343312494'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/wp7contrib-added-support-for-gzip.html' title='WP7Contrib: Added support for GZip compression to ResourceClient'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-WQTkDBam0Y4/TqR_4XqWdCI/AAAAAAAAAMA/6X8AwiTsSto/s72-c/GZip+1.png' height='72' width='72'/><thr:total>0</thr:total><georss:featurename>Hackney, London N16 0NU, UK</georss:featurename><georss:point>51.5618404 -0.0763918</georss:point><georss:box>51.5593724 -0.08132729999999999 51.5643084 -0.0714563</georss:box></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-3321108584328242528</id><published>2011-10-16T12:59:00.000-07:00</published><updated>2011-10-16T13:00:08.054-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7Contrib WP7 Url Development Rx'/><title type='text'>WP7Contrib: URL shortening in a WP7 app</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I needed the ability to shorten a URL for a WP7 app the other day so I could share a URL via the ShareLinkTask, more info about this task can be found on &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.sharelinktask(v=vs.92).aspx"&gt;MSDN&lt;/a&gt;. What follows is a solution to shortening a URL programmtically using &lt;a href="http://tinyurl.com/"&gt;tinyurl.com&lt;/a&gt;.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Obviously shortening a URL from a phone requires a connection, so this might not be applicable to a lot of apps. The problem is not the actual connection but the quality of said connection. When&amp;nbsp;tethered&amp;nbsp;or on WIFI the time required to shorten a URL is insignificant, but when on 3G the time is very noticable.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The solution I came up with allowed me to be abstracted away from the under lying HTTP request, infact it allowed me to write the code in 3 lines of code!&lt;/div&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleShortenButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;tinyUrlShortener&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Shorten&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;url&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;u &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;shortenedUrl&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; u&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The implementation for in the WP7Contrib is as follows, it uses the Rx (reactive extensions) async method to make the request over HTTP and process the response. If processing the response fails then the original URL is returned - if it fails to call the TinyUrl server it will return the original value as the shortened URL.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; IObservable&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Shorten&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; url&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsNullOrEmpty&lt;span style="color: #808030;"&gt;(&lt;/span&gt;url&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ArgumentException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Can reduce a null or empty url!&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;url&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;try&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;TinyUrlShortener: Url - '{0}'.&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; url&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Defer&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Create&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;obs &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            var disposable &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; BooleanDisposable&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;try&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                var requestUrl &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;http://tinyurl.com/api-create.php?url={0}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;propertyEncoder&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Encode&lt;span style="color: #808030;"&gt;(&lt;/span&gt;url&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;TinyUrlShortener: Tiny url - '{0}'.&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; requestUrl&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                var request &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;HttpWebRequest&lt;span style="color: #808030;"&gt;)&lt;/span&gt;WebRequestCreator&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ClientHttp&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Create&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Uri&lt;span style="color: #808030;"&gt;(&lt;/span&gt;requestUrl&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                request&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Method &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;GET&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                request&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AllowAutoRedirect &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                request&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CookieContainer &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CookieContainer&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                        &lt;br /&gt;                Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;FromAsyncPattern&lt;span style="color: #808030;"&gt;(&lt;/span&gt;request&lt;span style="color: #808030;"&gt;.&lt;/span&gt;BeginGetResponse&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ar &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: maroon; font-weight: bold;"&gt;try&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                        var shortenedUrl &lt;span style="color: #808030;"&gt;=&lt;/span&gt; url&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;disposable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsDisposed&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                        &lt;span style="color: maroon; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var response &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;HttpWebResponse&lt;span style="color: #808030;"&gt;)&lt;/span&gt;request&lt;span style="color: #808030;"&gt;.&lt;/span&gt;EndGetResponse&lt;span style="color: #808030;"&gt;(&lt;/span&gt;ar&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;response&lt;span style="color: #808030;"&gt;.&lt;/span&gt;StatusCode &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; HttpStatusCode&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OK&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                                &lt;span style="color: maroon; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var stream &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; StreamReader&lt;span style="color: #808030;"&gt;(&lt;/span&gt;response&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetResponseStream&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                                &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                                    shortenedUrl &lt;span style="color: #808030;"&gt;=&lt;/span&gt; stream&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ReadLine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                                &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;TinyUrlShortener: Shortened url - '{0}'.&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; shortenedUrl&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                        obs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnNext&lt;span style="color: #808030;"&gt;(&lt;/span&gt;shortenedUrl&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                        obs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnCompleted&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: maroon; font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;Exception exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                        var message &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;FailedRequest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                        obs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnError&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ServiceException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;message&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;catch&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Exception exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                var message &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;FailedRequest&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                obs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;OnError&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ServiceException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;message&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; disposable&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;Exception exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var message &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;TinyUrlShortener: Failed to shorten url, message - '{0}'.&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ServiceException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;message&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This has now been added to the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt;. There is an example of how to use this in the Spikes directory called 'UrlShortenerDemo'.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-3321108584328242528?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/3321108584328242528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/wp7contrib-url-shortening-in-wp7-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/3321108584328242528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/3321108584328242528'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/wp7contrib-url-shortening-in-wp7-app.html' title='WP7Contrib: URL shortening in a WP7 app'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><thr:total>0</thr:total><georss:featurename>18-56 Beatty Rd, Hackney, Greater London N16 8, UK</georss:featurename><georss:point>51.5564754566401 -0.076904296875</georss:point><georss:box>51.5515394566401 -0.086774796875 51.5614114566401 -0.067033796875</georss:box></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-7443668799040282189</id><published>2011-10-16T11:54:00.000-07:00</published><updated>2011-10-16T11:54:20.758-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 WP7Contrib Bing Maps Polygon Development'/><title type='text'>Drawing shapes on top of Bing Maps in a WP7 app</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Before I complete the '&lt;i&gt;How many pins can Bing Maps handle in a WP7 app...&lt;/i&gt;' set of &lt;a href="http://awkwardcoder.blogspot.com/2011/09/how-many-pins-can-bing-maps-handle-in.html"&gt;posts&lt;/a&gt;. I wanted to show how I'm drawing shapes on top of the Bing Maps control in WP7.&amp;nbsp;This is based around using the MapPolygon class in the&amp;nbsp;Microsoft.Phone.Controls.Maps namespace, more info on &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.mappolygon.aspx"&gt;MSDN&lt;/a&gt;. Basically this will drawn lines betweens the geo-locations defined in the collection exposed by the Locations property. You're also able to define other properties such as fill colour, stroke thinkness, opacity. With these you have the ability to really customize any polygon you render over the map control.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'm going to show how I&amp;nbsp;achieved&amp;nbsp;the following&amp;nbsp;screen shots&amp;nbsp;and how this is all based around using the well known Haversine formula with only the centre location of the visible bounding rectangle of the Bing Maps control:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-FVmWfsXIusU/TpnMGqvRDXI/AAAAAAAAAK0/nJ67RJbgI5Q/s1600/map+polygon+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-FVmWfsXIusU/TpnMGqvRDXI/AAAAAAAAAK0/nJ67RJbgI5Q/s640/map+polygon+1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A couple of things to note, UI design is not my forte (as &lt;a href="http://twitter.com/#!/RichGee"&gt;@RichGee&lt;/a&gt; will tell you) so the following is more about&amp;nbsp;how to achieve it than what it finally looks like and secondly I'm using the Haversine formula to calculate geo-locations. This formula is not the most accurate available, but for my purposes the 0.3% error factor is acceptable. '&lt;i&gt;Movable Type&lt;/i&gt;' has a great page about lat &amp;amp; long formulas and calculations, more info &lt;a href="http://www.movable-type.co.uk/scripts/latlong.html"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I've used MVVM pattern for this app so therefore I have a set of Model classes that are bounded to the View via the ViewModel. The app only has 1 View, 1 ViewModel and 1 Model class but the Model class uses both object orientated and&amp;nbsp;functional&amp;nbsp;techniques to achieve what I wanted.&lt;br /&gt;&lt;br /&gt;The View has the map control and polygon&amp;nbsp;defined &amp;nbsp;in XAML as follows:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-tPKI3KVbg60/TprGhmEXh0I/AAAAAAAAALs/cv91XMb1A68/s1600/polygon+xaml.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-tPKI3KVbg60/TprGhmEXh0I/AAAAAAAAALs/cv91XMb1A68/s1600/polygon+xaml.png" /&gt;&lt;/a&gt;&lt;/div&gt;As you can see the map Centre property is bound to the ViewModel and the Locations property of the MapPolygon is bound to the Polygon geo-locations collection on the ViewModel.&lt;br /&gt;&lt;br /&gt;The Shape Model class defines a couple of properties, one for the shape name and the second a function for calculating the geo-locations used to describe the polygon (shape). This is a function delegate because the geo-locations are generated dynamically at runtime and this depends on the current centre location of the map control.&lt;/div&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;sealed&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; Shape &lt;span style="color: #808030;"&gt;:&lt;/span&gt; BaseModel&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; name&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; polygonFunc&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; Name&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        get&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;name&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;        set&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SetPropertyAndNotify&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;ref&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;name&lt;span style="color: #808030;"&gt;,&lt;/span&gt; value&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Name&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; PolygonFunc&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        get&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygonFunc&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        set&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SetPropertyAndNotify&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;ref&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygonFunc&lt;span style="color: #808030;"&gt;,&lt;/span&gt; value&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;PolygonFunc&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Instances of this Model are populated in the ViewModel constructor using a set of static methods on a helper class. This helper class is where the smarts for calculating polygons is contained. As you can see from the code below I've created several different shapes in different sizes.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; MapViewModel&lt;span style="color: #808030;"&gt;(&lt;/span&gt;ILog log&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log &lt;span style="color: #808030;"&gt;=&lt;/span&gt; log&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygon &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;51.561811605968394&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt;&lt;span style="color: green;"&gt;0.0883626937866211&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Zoom &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;15&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;shapes &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ObservableCollection&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;Shape&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;No Shape&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; centre &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (50 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.050&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (250 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.250&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Square (500 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Circle (50 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Circle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.050&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Circle (250 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Circle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.250&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Circle (500 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Circle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Pentangle (500 m)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Pentangle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Star (5 points)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Star (6 points)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;6&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Star (7 points)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;7&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Star (8 points)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Star (9 points)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;9&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Star (10 points)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;10&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (4 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (5 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (5 sides, offset)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;36&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (6 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;6&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (7 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;7&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (8 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (9 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;9&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Shape &lt;span style="color: purple;"&gt;{&lt;/span&gt; Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Polygon (10 sides)&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; PolygonFunc &lt;span style="color: #808030;"&gt;=&lt;/span&gt; MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;10&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.500&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SelectedShape &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;shapes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;First&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This collection of Shapes is then bound to the View via the Shapes property on the ViewModel. The View uses this as part of ListPicker to allow the user to select the current Shape. When a Shape is selected the ViewModel raises a property notify changed event to indicate the currently selected Shape should be re-drawn. The important part is the static class MapFuncs, this is where the smarts are. It uses the Haversine formula to calculate the polygons. The Haversine method is shown below along with a couple of hepler methods for converting degrees to and from radians. The Haversine formula calculates the geo-location given a start geo-location, distance and bearing on a sphere, the sphere in case is the Earth:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; GeoCoordinate CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate startLocation&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; distance&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; bearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var lat1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;startLocation&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var long1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;startLocation&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var bar1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var angularDistance &lt;span style="color: #808030;"&gt;=&lt;/span&gt; distance &lt;span style="color: #808030;"&gt;/&lt;/span&gt; EarthRadius&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var lat2 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Asin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bar1&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var lon2 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; long1 &lt;span style="color: #808030;"&gt;+&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Atan2&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bar1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                    Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    var destinationLocation &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;RadianToDegree&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RadianToDegree&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lon2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; destinationLocation&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;PI &lt;span style="color: #808030;"&gt;*&lt;/span&gt; angle &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: green;"&gt;180.0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; RadianToDegree&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; angle &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;180.0&lt;/span&gt; &lt;span style="color: #808030;"&gt;/&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;PI&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As I said earlier, the formula is then used to calculate the geo-locations which describe the required polygon (shape).&lt;br /&gt;&lt;br /&gt;Method for creating polygon describing a Circle:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Circle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var radius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; diameter &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; location &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate the the location for each degree of a circle...&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var i &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; i &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;360&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; i&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;MapFuncs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; radius&lt;span style="color: #808030;"&gt;,&lt;/span&gt; i&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; func&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-OgshGJFdVLU/Tpqxir8CcMI/AAAAAAAAAK8/J4NGYENwRTw/s1600/polygon+circles.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="352" src="http://3.bp.blogspot.com/-OgshGJFdVLU/Tpqxir8CcMI/AAAAAAAAAK8/J4NGYENwRTw/s640/polygon+circles.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Method for creating polygon describing a Square:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Square&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; length&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; location &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate the mid points of the square...&lt;/span&gt;&lt;br /&gt;        var halfLength &lt;span style="color: #808030;"&gt;=&lt;/span&gt; length &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var north &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfLength&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var south &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfLength&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;180&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var east &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfLength&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var west &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfLength&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Use the mid points to calculate the corners of the square...&lt;/span&gt;&lt;br /&gt;        locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;north&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; west&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;north&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; east&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;south&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; east&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;south&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; west&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; func&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-oI0rfz9GrKM/Tpq6j1jsx8I/AAAAAAAAALE/f80O3n38H-A/s1600/polygon+squares.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="352" src="http://2.bp.blogspot.com/-oI0rfz9GrKM/Tpq6j1jsx8I/AAAAAAAAALE/f80O3n38H-A/s640/polygon+squares.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Method for creating any polygon, e.g. hexagon, heptagon, octagon etc:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Polygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt; sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; startAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; location &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var radius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; diameter &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var angle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: green;"&gt;360.00&lt;/span&gt; &lt;span style="color: #808030;"&gt;/&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var i &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; i &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt; i&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            var aggregatedAngle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;i&lt;span style="color: #808030;"&gt;*&lt;/span&gt;angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; startAngle&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; radius&lt;span style="color: #808030;"&gt;,&lt;/span&gt; aggregatedAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; func&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Sg19FDYu4eY/Tpq7o0PwEoI/AAAAAAAAALM/iZ8OiazHM88/s1600/polygon+polygons.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="210" src="http://4.bp.blogspot.com/-Sg19FDYu4eY/Tpq7o0PwEoI/AAAAAAAAALM/iZ8OiazHM88/s640/polygon+polygons.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The following 2 are the most interesting, they are also the most complicated - Star &amp;amp; Pentangle (pentagram). The method for creating a Star polygon allows the number of points to be defined as well as the diameter (size). The Pentangle is a special case of a Star, it gives you a more natural looking star image. Wikipedia describes a pentagram as '&lt;i&gt;the shape of a five-pointed star drawn with five straight strokes.&lt;/i&gt;'&lt;br /&gt;&lt;br /&gt;The difference between two is essential the ratio between the inner and outer points of the star - I'm sure there is a technical term for this but I'm not aware of the name. For the following Star polygons I've a ratio of 2/3 and for the Pentangle I've used 8/17 - this give the distinctive Pentangle shape:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-bce6mMpp0_M/TprEcQaJF_I/AAAAAAAAALc/hlS6gSd4LCU/s1600/pentangle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-bce6mMpp0_M/TprEcQaJF_I/AAAAAAAAALc/hlS6gSd4LCU/s1600/pentangle.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Method for creating a Star polygon:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt; sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt; sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; startAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; startAngle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;/&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt; sides&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; startAngle&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; ratio&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; func &lt;span style="color: #808030;"&gt;=&lt;/span&gt; location &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var outerPoints &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate the outer points, these lie on the circumference of the circle&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// described by the diameter...&lt;/span&gt;&lt;br /&gt;        var radius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; diameter &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var angle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: green;"&gt;360.00&lt;/span&gt; &lt;span style="color: #808030;"&gt;/&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var i &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; i &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt; i&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            var aggregatedAngle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;i &lt;span style="color: #808030;"&gt;*&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; startAngle&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            outerPoints&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; radius&lt;span style="color: #808030;"&gt;,&lt;/span&gt; aggregatedAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Distance between 2 outer points...&lt;/span&gt;&lt;br /&gt;        var distance &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;outerPoints&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetDistanceTo&lt;span style="color: #808030;"&gt;(&lt;/span&gt;outerPoints&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1000&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var side &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sqrt&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;radius &lt;span style="color: #808030;"&gt;*&lt;/span&gt; radius&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;distance &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;distance &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// Calculate the inner points and combine with outer points...&lt;/span&gt;&lt;br /&gt;        var halfAngle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; angle &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var i &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; i &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; sides&lt;span style="color: purple;"&gt;;&lt;/span&gt; i&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;+&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            var aggregatedAngle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;i &lt;span style="color: #808030;"&gt;*&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;startAngle &lt;span style="color: #808030;"&gt;+&lt;/span&gt; halfAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            var point &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CalculateUsingHaversine&lt;span style="color: #808030;"&gt;(&lt;/span&gt;location&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;side  &lt;span style="color: #808030;"&gt;*&lt;/span&gt; ratio&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; aggregatedAngle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;outerPoints&lt;span style="color: #808030;"&gt;[&lt;/span&gt;i&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;point&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; locations&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; func&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-4rBz7_XbgfM/Tpq9kOV9fjI/AAAAAAAAALU/290GdAaA4AU/s1600/polygon+stars.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="210" src="http://3.bp.blogspot.com/-4rBz7_XbgfM/Tpq9kOV9fjI/AAAAAAAAALU/290GdAaA4AU/s640/polygon+stars.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Method for creating a Pentangle polygon:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; Func&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;,&lt;/span&gt; LocationCollection&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Pentangle&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Star&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; diameter&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;/&lt;/span&gt;&lt;span style="color: #008c00;"&gt;17&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-q20cUDid97o/TprEvnxYNEI/AAAAAAAAALk/Rl_5RnMPFw8/s1600/polygon+pentangle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-q20cUDid97o/TprEvnxYNEI/AAAAAAAAALk/Rl_5RnMPFw8/s320/polygon+pentangle.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I included a couple of memory counters at the bottom of the demo app to observe the memory consumption when rendering polygons onto the map control. After showing 10 polygons on the map and then removing &amp;nbsp;the polygon the following memory usage was observed. I was a little surprised by the increase of over 14 Mb in peak memory usage. I could see there being issues when rendering multiple polygons on the map control.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-15WNhqTrnL8/TpseYYaNdOI/AAAAAAAAAL0/OCmYOOfQmAI/s1600/polygon+memory+usage.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-15WNhqTrnL8/TpseYYaNdOI/AAAAAAAAAL0/OCmYOOfQmAI/s1600/polygon+memory+usage.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Removing the polygon from the map control was also not as straight forward as expected. &amp;nbsp;I had to use the same pattern as described in this &lt;a href="http://awkwardcoder.blogspot.com/2011/10/removing-poly-line-from-bing-maps-on.html"&gt;post&lt;/a&gt;. Clearing the contents of the geo-locations collection did not work, I had to clear it then add a single value back into the collection. I ended up with the following functionality:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; LocationCollection Polygon&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    get&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Clear&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;BuildPolygon&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ForEach&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// If the 'no shape' is selected we need to force the polygon to be removed&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: dimgrey;"&gt;// this is done by adding a point, in this case the centre location.&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygon&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;centre&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;polygon&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The code makes use of the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt; for the base class for the ViewModel &amp;amp; Model classes and is referenced as an NuGet packages.&amp;nbsp;The code for this demo app is available on SkyDrive.&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/Blog%20Posts/PolygonDemo.zip?cid=8503dda7ad75860b&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-7443668799040282189?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/7443668799040282189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/drawing-shapes-on-top-of-bing-maps-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7443668799040282189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/7443668799040282189'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/drawing-shapes-on-top-of-bing-maps-in.html' title='Drawing shapes on top of Bing Maps in a WP7 app'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-FVmWfsXIusU/TpnMGqvRDXI/AAAAAAAAAK0/nJ67RJbgI5Q/s72-c/map+polygon+1.png' height='72' width='72'/><thr:total>0</thr:total><georss:featurename>18-56 Beatty Rd, Hackney, Greater London N16 8, UK</georss:featurename><georss:point>51.55642209198497 -0.07707595825195312</georss:point><georss:box>51.55148609198497 -0.08694645825195313 51.56135809198497 -0.06720545825195312</georss:box></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-6635329124553766060</id><published>2011-10-09T03:31:00.000-07:00</published><updated>2011-10-10T03:34:46.983-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 Bing Maps Development UK Crime'/><title type='text'>How many pins can Bing Maps handle in a WP7 app - part 2</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I wasn't planning this to span more than one &lt;a href="http://awkwardcoder.blogspot.com/2011/09/how-many-pins-can-bing-maps-handle-in.html"&gt;post&lt;/a&gt; but it has and there's a good chance there'll be a third focusing back on the UI and how you can improve this further. This post is going to focus on what you can do with the service layer to improve the performance when loading a lot of pins into the Bing Maps control in a WP7 app.&lt;br /&gt;&lt;br /&gt;To recap we reached a point where we are only showing the pins required for the bounding rectangle of the map control - even if the call to the service layer returned 500 hundred pins we were calculating which pins were&amp;nbsp;actually&amp;nbsp;visible and only adding them to the MapItemsControl class.&lt;br /&gt;&lt;br /&gt;This was working well from a UI and general app perspective - we're no longer blocking the UI thread and we aren't chewing through to much memory. The main problem with this approach is the inefficiency in&amp;nbsp;retrieving&amp;nbsp;data from the UK crime web services. The data returned by these services is centred around the a geo-location for a radius of 1 mile, put simply they return all the reported crimes within a mile of a geo-location. The test location returns over 1000 crime geo-locations, we only want to show a subset of these, probably 150 or so. The screenshot from the last post shows this perfectly:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-xLcdK4ej64Q/To8nydeQefI/AAAAAAAAAKc/QQINCqwlkD0/s1600/pins+2+-+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="612" src="http://2.bp.blogspot.com/-xLcdK4ej64Q/To8nydeQefI/AAAAAAAAAKc/QQINCqwlkD0/s640/pins+2+-+1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;When I moved the map a request for more data is being made, even if I only move the map a couple of scrolls it is making a new request for data centred around the new geo-location. What became obvious was the actual data being displayed for this movement had already been&amp;nbsp;requested&amp;nbsp;previously. This forms the basis of the in-efficiency -&amp;nbsp;requesting&amp;nbsp;data that has already been requested by the app.&lt;br /&gt;&lt;br /&gt;To recap we're getting the data when the ViewChangedEnd event is firing for the map control. We use the crime service in the service layer to request the data from the web services. It is then filtered before adding to the MapItemsControl class. I've shown a stripped down version of the call to the crime service in the service layer below:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleViewChangeEnd&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; MapEventArgs mapEventArgs&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var criterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; StreetLevelCrimeCriterion &lt;span style="color: purple;"&gt;{&lt;/span&gt; Latitude &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;map&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Longitude &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;map&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeSubscriber &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SearchCrimeRelatedStreetLevelCrime&lt;span style="color: #808030;"&gt;(&lt;/span&gt;criterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;result &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;What's required to prevent requesting the same data again and again (when scrolling) is caching in the service layer. The service layer should be able to workout what data you're requesting and then if the data has already been requested then it should return this already requested data instead of making a request to the&amp;nbsp;back-end&amp;nbsp;web services - standard caching pattern.&lt;br /&gt;&lt;br /&gt;Now the service layer did have a caching pattern at the end of the first post. The problem is the cache key was based on an exact geo-location (contained in the Criterion class). So it would cache the crimes for a mile around an exact geo-location for every request. As you can imagine the chances of 2 requests being made with the same geo-location are very small:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;var cacheKeyTuple &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CacheKeyTuple&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;NeighbourhoodCrimeCriterion&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        Name &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;SearchNeighbourhoodCrimes&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        Value &lt;span style="color: #808030;"&gt;=&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;DeepClone&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var cachedResult &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;cacheProvider&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Get&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;CacheKeyTuple&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;NeighbourhoodCrimeCriterion&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; NeighbourhoodCrimeResult&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cacheKeyTuple&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;cachedResult &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;UkCrimeService: SearchNeighbourhoodCrimes results retrieved from cache, hash code - {0}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetHashCode&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Return&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cachedResult&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AsObservable&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The screen shot below shows&amp;nbsp;how inefficient this is. When the app is started in location 1 all the crimes within a 1 mile are requested around the map centre point (shown by the pins inside the red circle). When the map is scrolled to locations 2 &amp;amp; 3 then it shouldn't have to request more data from the&amp;nbsp;back-end&amp;nbsp;web services it should be returned from the cache.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-r64m_JTJdWM/TpCO6Kc_y1I/AAAAAAAAAKk/Jd7linn1v4I/s1600/pins+2+-+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="612" src="http://2.bp.blogspot.com/-r64m_JTJdWM/TpCO6Kc_y1I/AAAAAAAAAKk/Jd7linn1v4I/s640/pins+2+-+3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So the output in visual studio is shown below, you can see the&amp;nbsp;inefficiency&amp;nbsp;in the multiple requests to the web services, I've also highlighted the geo-location information sent to the web services.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Wca1knPdaoQ/To8yswhxdiI/AAAAAAAAAKg/sF1olsMZras/s1600/pins+2+-+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-Wca1knPdaoQ/To8yswhxdiI/AAAAAAAAAKg/sF1olsMZras/s1600/pins+2+-+3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;To make this more efficient we have to apply some high school mathematics -&amp;nbsp;Pythagorean Theorem. We're going to use this to calculate the largest square we can get inside the circle described by the crimes returned from the back-end web service.&amp;nbsp;Once we know the length of the side of the square we can use&amp;nbsp;trigonometry to calculate the geo-locations of the corners of the square.&amp;nbsp;Finally when we know this we'll be able to calculate if the map control bounding rectangle is contained within the square, if it is then we don't need to make a request to the web services we can use the cached data, if not then a request will be made to the web services for more data.&lt;br /&gt;&lt;br /&gt;First, applying&amp;nbsp;Pythagorean Theorem, we are going to use metric units so instead of a radius of 1 mile it will be 1.60934 km.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-A6uLaajEySU/TpCe3iQfcfI/AAAAAAAAAKs/4EUU-uVSmHY/s1600/pytha.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-A6uLaajEySU/TpCe3iQfcfI/AAAAAAAAAKs/4EUU-uVSmHY/s1600/pytha.gif" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;By the symmetry of the diagram the center of the circle is on the diagonal AB of the square. The length of AB is 3.21868 km and the lengths of BC and CA are equal. The Pythagorean Theorem then says that&lt;br /&gt;&lt;br /&gt;(BC * BC) + (AC * AC) = (AB * AB)&lt;br /&gt;&lt;br /&gt;Hence&lt;br /&gt;&lt;br /&gt;(BC * BC) + (CA * CA) = 10.35990&lt;br /&gt;&lt;br /&gt;But since this is a square then BC is equal to AC, hence&lt;br /&gt;&lt;br /&gt;2 * (BC * BC) &amp;nbsp;= 10.35990&lt;br /&gt;&lt;br /&gt;and therefore&lt;br /&gt;&lt;br /&gt;|(BC * BC) &amp;nbsp;= 5.17995&lt;br /&gt;&lt;br /&gt;Taking the square root on my calculator I get&lt;br /&gt;&lt;br /&gt;BC = 2.27595&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The square has the sides of length&amp;nbsp;2.27595 Km.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Second, we use&amp;nbsp;trigonometry to calculate the geo-locations of the 4 corners of the square. We use the following Haversine&amp;nbsp;formula to calculate these, don't worry I've implemented this in code. It's shown here for completeness:&lt;br /&gt;&lt;br /&gt;&lt;table style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: collapse; margin-top: 1em;"&gt;&lt;tbody&gt;&lt;tr style="vertical-align: baseline;"&gt;&lt;td style="max-width: 64em; padding-bottom: 0.2em; padding-left: 0.2em; padding-right: 0.2em; padding-top: 0.2em;"&gt;&lt;/td&gt;&lt;td class="formula" style="font-family: 'Times New Roman', Times, serif; font-size: 1.2em; max-width: 64em; padding-bottom: 0.2em; padding-left: 0.2em; padding-right: 0.2em; padding-top: 0.2em;"&gt;lat&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;2&lt;/sub&gt;&amp;nbsp;= asin(sin(lat&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;1&lt;/sub&gt;)*cos(d/R) + cos(lat&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;1&lt;/sub&gt;)*sin(d/R)*cos(θ))&lt;/td&gt;&lt;/tr&gt;&lt;tr style="vertical-align: baseline;"&gt;&lt;td style="max-width: 64em; padding-bottom: 0.2em; padding-left: 0.2em; padding-right: 0.2em; padding-top: 0.2em;"&gt;&lt;/td&gt;&lt;td class="formula" style="font-family: 'Times New Roman', Times, serif; font-size: 1.2em; max-width: 64em; padding-bottom: 0.2em; padding-left: 0.2em; padding-right: 0.2em; padding-top: 0.2em;"&gt;lon&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;2&lt;/sub&gt;&amp;nbsp;= lon&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;1&lt;/sub&gt;&amp;nbsp;+ atan2(sin(θ)*sin(d/R)*cos(lat&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;1&lt;/sub&gt;), cos(d/R)−sin(lat&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;1&lt;/sub&gt;)*sin(lat&lt;sub style="bottom: -0.25em; font-size: 0.75em; line-height: 0; position: relative; top: 0.8ex; vertical-align: 0px;"&gt;2&lt;/sub&gt;))&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;θ is the bearing (in radians, clockwise from north);&lt;br /&gt;d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius&lt;br /&gt;&lt;br /&gt;Finally, these have been implemented in the CircularLocation class. It allows the setting of the radius and centre point and it will calculate the largest contained rectangle inside the described circle. The full implementation is shown below:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;sealed&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; CircularLocation&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;const&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; EarthRadius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;6371&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; GeoCoordinate centerPoint&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; radius&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; LocationRect containedRect&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; GeoCoordinate CenterPoint&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        get&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; centerPoint&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;        set&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;centerPoint &lt;span style="color: #808030;"&gt;=&lt;/span&gt; value&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;containedRect &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; Radius&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        get&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;radius&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;        set&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;radius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; value&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;containedRect &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; LocationRect ContainedRect&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        get&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;containedRect &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;containedRect &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateContainedRect&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;containedRect&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;bool&lt;/span&gt; IsRectangleContained&lt;span style="color: #808030;"&gt;(&lt;/span&gt;LocationRect boundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var containedRect &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ContainedRect&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;North &lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; containedRect&lt;span style="color: #808030;"&gt;.&lt;/span&gt;North&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;East &lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; containedRect&lt;span style="color: #808030;"&gt;.&lt;/span&gt;East&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;South &lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt; containedRect&lt;span style="color: #808030;"&gt;.&lt;/span&gt;South&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;boundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;West &lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt; containedRect&lt;span style="color: #808030;"&gt;.&lt;/span&gt;West&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; LocationRect CalculateContainedRect&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var hypotenuse &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;radius&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var side &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sqrt&lt;span style="color: #808030;"&gt;(&lt;/span&gt;hypotenuse &lt;span style="color: #808030;"&gt;*&lt;/span&gt; hypotenuse &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var halfSide &lt;span style="color: #808030;"&gt;=&lt;/span&gt; side &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var directNorth &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateDestination&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;centerPoint&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfSide&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var directSouth &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateDestination&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;centerPoint&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfSide&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;180&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var directEast &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateDestination&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;centerPoint&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfSide&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;90&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var directWest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateDestination&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;centerPoint&lt;span style="color: #808030;"&gt;,&lt;/span&gt; halfSide&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;270&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationRect&lt;span style="color: #808030;"&gt;(&lt;/span&gt;directNorth&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; directWest&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; directSouth&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; directEast&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; GeoCoordinate CalculateDestination&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate startLocation&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; distance&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; bearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var lat1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;startLocation&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var long1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;startLocation&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var bar1 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bearing&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var angularDistance &lt;span style="color: #808030;"&gt;=&lt;/span&gt; distance &lt;span style="color: #808030;"&gt;/&lt;/span&gt; EarthRadius&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var lat2 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Asin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bar1&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var lon2 &lt;span style="color: #808030;"&gt;=&lt;/span&gt; long1 &lt;span style="color: #808030;"&gt;+&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Atan2&lt;span style="color: #808030;"&gt;(&lt;/span&gt;Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;bar1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                                        Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cos&lt;span style="color: #808030;"&gt;(&lt;/span&gt;angularDistance&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat1&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;*&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Sin&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        var destinationLocation &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;RadianToDegree&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lat2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RadianToDegree&lt;span style="color: #808030;"&gt;(&lt;/span&gt;lon2&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; destinationLocation&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; DegreeToRadian&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;PI &lt;span style="color: #808030;"&gt;*&lt;/span&gt; angle &lt;span style="color: #808030;"&gt;/&lt;/span&gt; &lt;span style="color: green;"&gt;180.0&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; RadianToDegree&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;double&lt;/span&gt; angle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; angle &lt;span style="color: #808030;"&gt;*&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;180.0&lt;/span&gt; &lt;span style="color: #808030;"&gt;/&lt;/span&gt; Math&lt;span style="color: #808030;"&gt;.&lt;/span&gt;PI&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This class is then used in the modified crime service as the key for an item added to the cache. When a request is made to the crime service it will recurse the keys added to the cache looking for an instance that&lt;br /&gt;can contain the requested bounding rectangle of the map control - simple!&lt;br /&gt;&lt;br /&gt;Obviously&amp;nbsp;how the key is created and added to the cache has been modified, but this is nothing more than creating&amp;nbsp;of an instance of the CircularLocation class and setting the required properties. Shown below is the crime service method.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; IObservable&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;StreetLevelCrimeResult&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; SearchStreetLevelCrime&lt;span style="color: #808030;"&gt;(&lt;/span&gt;StreetLevelCrimeCriterion criterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;try&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var centrePoint &lt;span style="color: #808030;"&gt;=&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;BoundingRectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;        var keys &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;cacheProvider&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Keys&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;CircularLocation&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var key &lt;span style="color: #808030;"&gt;=&lt;/span&gt; keys&lt;span style="color: #808030;"&gt;.&lt;/span&gt;FirstOrDefault&lt;span style="color: #808030;"&gt;(&lt;/span&gt;k &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; k&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsRectangleContained&lt;span style="color: #808030;"&gt;(&lt;/span&gt;criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;BoundingRectangle&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;key &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            var cachedResult &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;cacheProvider&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Get&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;CircularLocation&lt;span style="color: #808030;"&gt;,&lt;/span&gt; StreetLevelCrimeResult&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;UkCrimeService: SearchStreetLevelCrime results retrieved from cache, hash code - {0}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetHashCode&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; Observable&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Return&lt;span style="color: #808030;"&gt;(&lt;/span&gt;cachedResult&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AsObservable&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt;&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt; @&lt;span style="color: maroon; font-weight: bold;"&gt;params&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt;&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt; &lt;span style="color: purple;"&gt;{&lt;/span&gt; propertyEncoder&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Encode&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centrePoint&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; propertyEncoder&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Encode&lt;span style="color: #808030;"&gt;(&lt;/span&gt;centrePoint&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; resourceHandlerFactory&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Create&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ForType&lt;span style="color: #808030;"&gt;(&lt;/span&gt;ResourceType&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Json&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;UseUrlForGet&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;settings&lt;span style="color: #808030;"&gt;.&lt;/span&gt;StreetCrimeUrl&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;WithBasicAuthentication&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;settings&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Username&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;settings&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Password&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Get&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;List&lt;span style="color: #808030;"&gt;&amp;amp;lt;&lt;/span&gt;CrimeRelated&lt;span style="color: #808030;"&gt;.&lt;/span&gt;StreetLevel&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Resources&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Result&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;@&lt;span style="color: maroon; font-weight: bold;"&gt;params&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Select&lt;span style="color: #808030;"&gt;(&lt;/span&gt;response &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                var result &lt;span style="color: #808030;"&gt;=&lt;/span&gt; ProcessResponse&lt;span style="color: #808030;"&gt;(&lt;/span&gt;response&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                var circularLocation &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; CircularLocation &lt;span style="color: purple;"&gt;{&lt;/span&gt; CenterPoint &lt;span style="color: #808030;"&gt;=&lt;/span&gt; centrePoint&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Radius &lt;span style="color: #808030;"&gt;=&lt;/span&gt; SearchDistance &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                var containedRect &lt;span style="color: #808030;"&gt;=&lt;/span&gt; circularLocation&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ContainedRect&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;UkCrimeService: SearchStreetLevelCrime contained rectangle - {0}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; containedRect&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;cacheProvider&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;circularLocation&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;cacheTimeout&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; result&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;Exception exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        var message &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;FailedPoliceStreetLevelCrime&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Exception&lt;span style="color: #808030;"&gt;(&lt;/span&gt;message&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exn&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now when I run the app I get better performance when scrolling within the calculated contained rectangle. Only when you're no longer inside the contained rectangle is a request for more data made to the back-end web services.&amp;nbsp;This can be observed in the output window of visual studio. The highlighted area shows the cached results being returned, eventually I scroll outside of the contained rectangle and another request to the back-end web services is made.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-S_8C52q-CFE/TpDAq3TefbI/AAAAAAAAAKw/TpwTZXOymdM/s1600/pins+2+-+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-S_8C52q-CFE/TpDAq3TefbI/AAAAAAAAAKw/TpwTZXOymdM/s1600/pins+2+-+5.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Back to the original question - How many pins can Bing Maps handle in a WP7 app?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This post hasn't really changed the answer to this question from the previous post, it has shown you how you can be more efficient with your requesting of data when you're only showing a subset of the returned data.&lt;br /&gt;&lt;br /&gt;Part3 will focus back on the UI and how conflation of pins can will help the user experience.&lt;br /&gt;&lt;br /&gt;I've put the code for this version up on SkyDrive, you'll need a username &amp;amp; password for the UK crime stats service to run the code.&lt;br /&gt;&lt;br /&gt;&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/Blog%20Posts/HowManyPins2.zip?cid=8503dda7ad75860b&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-6635329124553766060?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/6635329124553766060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/how-many-pins-can-bing-maps-handle-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/6635329124553766060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/6635329124553766060'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/how-many-pins-can-bing-maps-handle-in.html' title='How many pins can Bing Maps handle in a WP7 app - part 2'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-xLcdK4ej64Q/To8nydeQefI/AAAAAAAAAKc/QQINCqwlkD0/s72-c/pins+2+-+1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-8708190191178980837</id><published>2011-10-05T13:12:00.000-07:00</published><updated>2011-10-06T00:29:54.414-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 Bing Maps Development Network HTTP'/><title type='text'>Observing network traffic for Bing Maps control in WP7</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Using the Bing Maps control in a WP7 app can incur a rather large memory cost when compared to the rest of an app. Typically I see an initial cost of approximately 8 Mb to show a full screen map when the zoom level is set to 16. This is not a concern, and in my opinion this shouldn't be either. Whats interesting to see is whats happen under the covers from a network perspective and to see if I can see any correlation. None of the following has any scientific basis, more a set of observations.&lt;br /&gt;&lt;br /&gt;This is very simple to do, all we need to do is configure the WIFI on the device and then reconfigure Fiddler for remote connections. You can find all the detailed required in this great &lt;a href="http://blogs.msdn.com/b/fiddler/archive/2011/01/09/debugging-windows-phone-7-device-traffic-with-fiddler.aspx"&gt;post&lt;/a&gt;&amp;nbsp;by Eric Law.&lt;br /&gt;&lt;br /&gt;For the observations I used a modified version of the app from the 'How many pins...' &lt;a href="http://awkwardcoder.blogspot.com/2011/09/how-many-pins-can-bing-maps-handle-in.html"&gt;post&lt;/a&gt; I did a couple of weeks ago. It only shows the map control it does not display any pins.&lt;br /&gt;&lt;br /&gt;When the app is initially installed and run for the first time I'm observing the following network traffic in Fiddler:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-KkHUgxMfDM4/Toyz-o71OLI/AAAAAAAAAKM/vr6ATmp2H-M/s1600/bing+maps+http+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="360" src="http://2.bp.blogspot.com/-KkHUgxMfDM4/Toyz-o71OLI/AAAAAAAAAKM/vr6ATmp2H-M/s640/bing+maps+http+1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;You can see there are approximately 35 requests for tiles when the app initially starts, as expected the low resolution tiles are requested first followed by higher resolution. Interestingly the largest tile in png format is only 25 Kb in size.Even if we multiplied 35 by 25 we don't get anywhere near the 8 Mb figure. Infact it only totals about 875 Kb. What we have to remember is, PNG is a bitmapped image format employing a lossless compression format.&lt;br /&gt;&lt;br /&gt;Lets see the cost of loading one of these single tiles into an Image control, shown below is the tile and the a test app which loads the tile into the Image control when button the is clicked. I've also stuck on a couple of memory counters.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-dPo82QPdoAc/Toys1eq8YDI/AAAAAAAAAKI/w9wmTPemWys/s1600/bing+maps+http+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="427" src="http://3.bp.blogspot.com/-dPo82QPdoAc/Toys1eq8YDI/AAAAAAAAAKI/w9wmTPemWys/s640/bing+maps+http+2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;You can see from loading the image explicitly there is a memory cost associated approximately 600 Kb for this tile. If this was multipled by 25 we'd get a total memory cost of 15 Mb. This is a theoretical total figure but even if it was approaching half this size for the tiles downloaded in the Fiddler screenshot you can see the Bing Maps control is already managing the memory allocated internal already without even approaching the 90 Mb limit.&lt;br /&gt;&lt;br /&gt;The next observation was around restarting the application. I observed the tiles were being cached for the app. Whether these are cached by the control for all apps or on a per app basis is unclear. Each response for a tile has HTTP caching directives and these state the tile can be cached for a year - 365 days.&amp;nbsp;The screenshot show 2 restarts of the application, once immediately after closing the app and the second after rebooting the device.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-nSWDPpp12iY/ToynOygrYmI/AAAAAAAAAKE/Ppbz9szhaKM/s1600/bing+maps+http+3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="276" src="http://3.bp.blogspot.com/-nSWDPpp12iY/ToynOygrYmI/AAAAAAAAAKE/Ppbz9szhaKM/s640/bing+maps+http+3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The final observation is the most obvious as I scroll &amp;amp; zoom in and out of the map, I see alot of requests for tiles as expected, the interesting part is it appears the control makes maximum of 5 simultaneous requests for tiles. This was pretty hard to capture but the following screenshot shows 3 outstsanding requests:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XlGpjDOO5Bw/Toy45DuMQLI/AAAAAAAAAKU/HJwT7RDKeCc/s1600/bing+maps+http+5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="360" src="http://1.bp.blogspot.com/-XlGpjDOO5Bw/Toy45DuMQLI/AAAAAAAAAKU/HJwT7RDKeCc/s640/bing+maps+http+5.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-8708190191178980837?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/8708190191178980837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/observing-network-traffic-for-bing-maps.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8708190191178980837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8708190191178980837'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/observing-network-traffic-for-bing-maps.html' title='Observing network traffic for Bing Maps control in WP7'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-KkHUgxMfDM4/Toyz-o71OLI/AAAAAAAAAKM/vr6ATmp2H-M/s72-c/bing+maps+http+1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-8642238237855355199</id><published>2011-10-02T08:19:00.000-07:00</published><updated>2011-10-02T08:36:16.250-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 WP7Contrib Bing Maps Development'/><title type='text'>Removing poly line from Bing Maps on WP7</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Showing a route line for a&amp;nbsp;journey on a Bing Maps control in a WP7 app is relatively easy, especially if you use the &lt;a href="http://www.codeplex.com/"&gt;WP7Contrib&lt;/a&gt; Bing Maps Wrapper service to call out to the Bing Maps RESTful API. It's not quite so easy to remove a route line from the control once displayed.&lt;br /&gt;&lt;br /&gt;The background to this is in our WP7 app&amp;nbsp;&lt;a href="zune://navigate/?phoneappid=2d496451-8fd3-426f-b4dd-3d323781931d"&gt;FINDaPAD&lt;/a&gt;&amp;nbsp;(you'll need Zune installed)&amp;nbsp;we have a page which shows the route to a property. We offer a driving route and a walking route - if it's walking distance! We don't display these routes together, they are mutually exclusive. When either of the icons is clicked to calculate the route we remove the existing route and display the new route once it has been calculated. The couple of screen shots below show 2 different routes between the same start &amp;amp; end locations depending whether you are driving or walking.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-2mEDr0SE1F4/Toh3b6y6XoI/AAAAAAAAAJk/f1tI0PlsKw4/s1600/route+line+findapad.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="588" src="http://1.bp.blogspot.com/-2mEDr0SE1F4/Toh3b6y6XoI/AAAAAAAAAJk/f1tI0PlsKw4/s640/route+line+findapad.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Shown below is a quick demo I knocked up to show the problem in more detail. This app displays a driving or walking app between the 2 UK cities Oxford &amp;amp; Cambridge. It also has a couple of buttons for &lt;i&gt;Clearing&lt;/i&gt; the route line and what I call &lt;i&gt;Resetting &lt;/i&gt;the route line. This is very similar to what we have in FINDaPAD.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-wkCiKyGPVzs/Toh5cGDEVyI/AAAAAAAAAJo/vzYIapx8wyw/s1600/route+line3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="590" src="http://3.bp.blogspot.com/-wkCiKyGPVzs/Toh5cGDEVyI/AAAAAAAAAJo/vzYIapx8wyw/s640/route+line3.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The&amp;nbsp;MapPolyline class in the&amp;nbsp;Microsoft.Phone.Controls.Maps namespace use the Location property for the line drawn on top of the map. This is not a generic collection like IList&lt;t&gt; or ObservableCollection&lt;t&gt; it is of type LocationCollection coming from the same namespace.&amp;nbsp;&lt;/t&gt;&lt;/t&gt;&lt;br /&gt;&lt;t&gt;&lt;t&gt;&lt;br /&gt;&lt;/t&gt;&lt;/t&gt;&lt;br /&gt;&lt;t&gt;&lt;t&gt;So my definition of &lt;i&gt;Clearing &lt;/i&gt;would be clearing contents of this collection. This is done in the 'Clear Route' button click event handler:&lt;/t&gt;&lt;/t&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleClearRouteButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeResult&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Empty&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMapRouteLine&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Clear&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Unfortunately this doesn't do what I'd expected, it does not remove the overlaid map polyline. As you can see from the screenshot below the text showing the number of points and total distance has been removed but the line hasn't.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-G5gHX-gCbAc/Toh7mPZrtsI/AAAAAAAAAJs/J9YGUQPomTo/s1600/route+line4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-G5gHX-gCbAc/Toh7mPZrtsI/AAAAAAAAAJs/J9YGUQPomTo/s640/route+line4.PNG" width="346" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;To get this to work I had to do what I define as &lt;i&gt;Resetting &lt;/i&gt;the clearing of the collection but then adding back in a single value. It doesn't have to any particular value it could be anything that is a valid geo-location - not GeoCoordinate.Unknown.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleResetRouteButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeResult&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Empty&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMapRouteLine&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMap&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I literally resetting the collection and adding the centre point of the map back in as the start of the poly line, this gives the expected UI response when 'Reset Route' button is clicked:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-x_v1PX4AGt4/Toh9Ak3n3PI/AAAAAAAAAJw/Xm6LeLHiVWo/s1600/route+line5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-x_v1PX4AGt4/Toh9Ak3n3PI/AAAAAAAAAJw/Xm6LeLHiVWo/s640/route+line5.PNG" width="358" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I've observed the same behaviour when using the MVVM pattern (FINDaPAD) or a code behind as in the above demo. I've included the code below for the demo, including the XAML.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Grid&lt;/span&gt; &lt;span style="color: #274796;"&gt;x:Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;ContentPanel&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #274796;"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;1&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #274796;"&gt;Margin&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;12,0,12,0&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #666616;"&gt;Microsoft_Phone_Controls_Maps&lt;/span&gt;&lt;span style="color: purple;"&gt;:&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Map&lt;/span&gt; &lt;span style="color: #274796;"&gt;x:Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;routeMap&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;Height&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;400&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Top&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;ZoomBarVisibility&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Collapsed&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;CopyrightVisibility&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Visible&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;ZoomLevel&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;8&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;AnimationLevel&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;UserInput&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Stretch&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                               &lt;span style="color: #274796;"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Stretch&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #666616;"&gt;Microsoft_Phone_Controls_Maps&lt;/span&gt;&lt;span style="color: purple;"&gt;:&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;MapPolyline&lt;/span&gt; &lt;span style="color: #274796;"&gt;x:Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;routeMapRouteLine&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                                           &lt;span style="color: #274796;"&gt;Stroke&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Green&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                                           &lt;span style="color: #274796;"&gt;StrokeThickness&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;6&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                                                           &lt;span style="color: #274796;"&gt;Opacity&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;0.7&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #666616;"&gt;Microsoft_Phone_Controls_Maps&lt;/span&gt;&lt;span style="color: purple;"&gt;:&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Map&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Button&lt;/span&gt; &lt;span style="color: #274796;"&gt;Content&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Driving Route&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Height&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;72&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Margin&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;0,463,232,0&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;drivingButton&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Top&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Click&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;HandleDrivingButtonClick&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Button&lt;/span&gt; &lt;span style="color: #274796;"&gt;Content&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Walking Route&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Height&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;72&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Margin&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;209,463,6,0&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;walkingButton&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Top&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Click&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;HandleWalkingButtonClick&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;TextBlock&lt;/span&gt; &lt;span style="color: #274796;"&gt;Height&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;30&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                       &lt;span style="color: #274796;"&gt;Margin&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;12,427,6,0&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                       &lt;span style="color: #274796;"&gt;Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;routeResult&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                       &lt;span style="color: #274796;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Top&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Button&lt;/span&gt; &lt;span style="color: #274796;"&gt;Content&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Clear Route&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Height&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;72&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Left&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Margin&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;0,529,0,0&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;clearRouteButton&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Top&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Width&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;224&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Click&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;HandleClearRouteButtonClick&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Button&lt;/span&gt; &lt;span style="color: #274796;"&gt;Content&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Reset Route&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Height&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;72&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Left&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Margin&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;209,529,0,0&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Name&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;resetRouteButton&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Top&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Width&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;241&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #274796;"&gt;Click&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;HandleResetRouteButtonClick&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;Grid&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As I said earlier I've used the Bing Maps Wrapper service from the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt;, you can find out more about calculating routes and all the other functionality by reading a couple of &lt;a href="http://blogs.xamlninja.com/wp7contrib/wp7contrib-bing-service-wrapper-part-ii-route"&gt;posts&lt;/a&gt; by &lt;a href="http://blogs.xamlninja.com/"&gt;RichGee&lt;/a&gt;&amp;nbsp;and &lt;a href="http://awkwardcoder.blogspot.com/2011/09/wp7contrib-criterion-factory-route.html"&gt;this&lt;/a&gt; by me.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; partial &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; MainPage &lt;span style="color: #808030;"&gt;:&lt;/span&gt; PhoneApplicationPage&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;const&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; RouteResultFormat &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Route Points: {0}, Distance: {1} {2}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;const&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; RouteFailedFormat &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Route Failed: {0}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; IBingMapsService bingMapsService&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; IRouteSearchCriterion drivingCriterion&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;readonly&lt;/span&gt; IRouteSearchCriterion walkingCriterion&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; MainPage&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        InitializeComponent&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;bingMapsService &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; BingMapsService&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"Your credentials&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon;"&gt;"Your app id&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var start &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;51.754240074033525&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt;&lt;span style="color: green;"&gt;1.25244140625&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        var end &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;52.19413974159756&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: green;"&gt;0.1318359375&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        var waypoints &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: purple;"&gt;{&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; WayPoint &lt;span style="color: purple;"&gt;{&lt;/span&gt; Point &lt;span style="color: #808030;"&gt;=&lt;/span&gt; start &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; WayPoint &lt;span style="color: purple;"&gt;{&lt;/span&gt; Point &lt;span style="color: #808030;"&gt;=&lt;/span&gt; end &lt;span style="color: purple;"&gt;}&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;drivingCriterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CriterionFactory&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;waypoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ModeOfTravel&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Driving&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;walkingCriterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CriterionFactory&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;waypoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ModeOfTravel&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Walking&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMap&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; GeoCoordinate&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: green;"&gt;51.88369680508255&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;-&lt;/span&gt;&lt;span style="color: green;"&gt;0.4140472412109375&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMap&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ZoomLevel &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;8&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleDrivingButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeProgressBar&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsIndeterminate &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;bingMapsService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateARoute&lt;span style="color: #808030;"&gt;(&lt;/span&gt;drivingCriterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;UpdateRouteResult&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: purple;"&gt;{&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeProgressBar&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsIndeterminate &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleWalkingButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeProgressBar&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsIndeterminate &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;bingMapsService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateARoute&lt;span style="color: #808030;"&gt;(&lt;/span&gt;walkingCriterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;UpdateRouteResult&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: purple;"&gt;{&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeProgressBar&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsIndeterminate &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; UpdateRouteResult&lt;span style="color: #808030;"&gt;(&lt;/span&gt;RouteSearchResult result&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;HasError&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeResult&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;RouteFailedFormat&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ErrorDetails&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;HasPoints&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeResult&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;RouteResultFormat&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Points&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TravelDistance&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;DistanceUnit&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMapRouteLine&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Points&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMap&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ZoomLevel &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;8&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleClearRouteButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeResult&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Empty&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMapRouteLine&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Clear&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleResetRouteButtonClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeResult&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Empty&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMapRouteLine&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Locations &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; LocationCollection &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeMap&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-8642238237855355199?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/8642238237855355199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/removing-poly-line-from-bing-maps-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8642238237855355199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8642238237855355199'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/10/removing-poly-line-from-bing-maps-on.html' title='Removing poly line from Bing Maps on WP7'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-2mEDr0SE1F4/Toh3b6y6XoI/AAAAAAAAAJk/f1tI0PlsKw4/s72-c/route+line+findapad.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-8936884770333538344</id><published>2011-09-29T04:39:00.000-07:00</published><updated>2011-09-29T04:41:25.448-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 WP7Contrib CodePlex Bing Maps Development'/><title type='text'>WP7Contrib: Criterion Factory - calculating a Route</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Carrying on my &lt;a href="http://awkwardcoder.blogspot.com/2011/08/wp7contrib-bing-maps-rest-services.html"&gt;series&lt;/a&gt; about the Criterion Factory in the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt; I thought I'd show the how we do a route search. We support multiple Criterion Factory methods for creating criterion these all depend on how much information you have available.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Calculating a route using Bing Maps REST API can be tricky and confusing there are over 10 optional parameters which you could configure to get a route between 2 locations. As with other sets of method on the Criterion Factory we've attempt to reduce the complexity by providing this abstraction.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Shown below are the methods on the Criterion Factory (for route search). As you can see all of the overloaded methods are rooted to final method which validates the Waypoints parameter. These are used like all other Criterion Factory methods to make creating criterion easier for use with the Bing Maps Wrapper service.&lt;/div&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;#region CreateRouteSearch&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; IRouteSearchCriterion CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; wayPoints&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;wayPoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ModeOfTravel&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Driving&lt;span style="color: #808030;"&gt;,&lt;/span&gt; DistanceUnit&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Kilometer&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutePathOutput&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Points&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; TimeType&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Departure&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; IRouteSearchCriterion CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; wayPoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ModeOfTravel modeOfTravel&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;wayPoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; modeOfTravel&lt;span style="color: #808030;"&gt;,&lt;/span&gt; DistanceUnit&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Kilometer&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutePathOutput&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Points&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; TimeType&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Departure&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; IRouteSearchCriterion CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; wayPoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ModeOfTravel modeOfTravel&lt;span style="color: #808030;"&gt;,&lt;/span&gt; DistanceUnit distanceUnit&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Optimize? optimize&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;wayPoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; modeOfTravel&lt;span style="color: #808030;"&gt;,&lt;/span&gt; distanceUnit&lt;span style="color: #808030;"&gt;,&lt;/span&gt; optimize&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutePathOutput&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Points&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; TimeType&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Departure&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;static&lt;/span&gt; IRouteSearchCriterion CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;IList&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; wayPoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; ModeOfTravel modeOfTravel&lt;span style="color: #808030;"&gt;,&lt;/span&gt; DistanceUnit distanceUnit&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Optimize? optimize&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Avoid avoid&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt;? heading&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutePathOutput routePathOutput&lt;span style="color: #808030;"&gt;,&lt;/span&gt; DateTime? dateTime&lt;span style="color: #808030;"&gt;,&lt;/span&gt; TimeType timeType&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;int&lt;/span&gt;? maxSolutions&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt; pointOfInterest&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;wayPoints &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;null&lt;/span&gt; || wayPoints&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; ArgumentException&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Minimum number of WayPoints is 2.&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;wayPoints&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var criterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; RouteSearchCriterion&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        TravelMode &lt;span style="color: #808030;"&gt;=&lt;/span&gt; modeOfTravel&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        DistanceUnit &lt;span style="color: #808030;"&gt;=&lt;/span&gt; distanceUnit&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        Optimize &lt;span style="color: #808030;"&gt;=&lt;/span&gt; optimize&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        Avoid &lt;span style="color: #808030;"&gt;=&lt;/span&gt; avoid ?? &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Avoid&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        Heading &lt;span style="color: #808030;"&gt;=&lt;/span&gt; heading&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        PathOutput &lt;span style="color: #808030;"&gt;=&lt;/span&gt; routePathOutput&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        DateTime &lt;span style="color: #808030;"&gt;=&lt;/span&gt; dateTime&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        TimeType &lt;span style="color: #808030;"&gt;=&lt;/span&gt; timeType&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        MaxSolutions &lt;span style="color: #808030;"&gt;=&lt;/span&gt; maxSolutions&lt;span style="color: #808030;"&gt;.&lt;/span&gt;HasValue ? maxSolutions&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GetValueOrDefault&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;:&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;        PointOfInterest &lt;span style="color: #808030;"&gt;=&lt;/span&gt; pointOfInterest&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;WayPoints&lt;span style="color: #808030;"&gt;.&lt;/span&gt;AddRange&lt;span style="color: #808030;"&gt;(&lt;/span&gt;wayPoints&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; criterion&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;#endregion&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;These methods allow you to easily create the required criterion for the Bing Maps Wrapper service. Obviously as your requirement gets more detailed you can specify travel types, places to avoid, road types to avoid etc.&lt;br /&gt;&lt;br /&gt;The important and probably most complex parameter is the Waypoint list. As the names suggest all this is a set of location the route must contain. I hope its obvious but this list must contain at least 2 items - the start and destination locations for the route, you can't really have a route without these!&lt;br /&gt;&lt;br /&gt;A Waypoint is simple the notion of a place of interest. It can be either exact geo-location specified by latitude &amp;amp; longitude, a landmark specified by a place name and\or post code or an address. Specifying a geo-location would be the most accurate but any of them will do.&lt;br /&gt;&lt;br /&gt;The code below shows easy it is to get a route between 2 places with the Bing Maps Wrapper service - 8 lines of code including creating the criterion. This code is from an example called 'RouteSearch' in the Spikes directory of the WP7Contrib.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleCalculateRouteClick&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; RoutedEventArgs e&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var waypoints &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; WayPoint &lt;span style="color: purple;"&gt;{&lt;/span&gt;Landmark &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Landmark &lt;span style="color: purple;"&gt;{&lt;/span&gt;AreaName &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;startText&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; WayPoint &lt;span style="color: purple;"&gt;{&lt;/span&gt;Landmark &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; Landmark &lt;span style="color: purple;"&gt;{&lt;/span&gt;AreaName &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;finishText&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var criterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CriterionFactory&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;waypoints&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;   &amp;nbsp;&lt;/pre&gt;&lt;pre style="background: #ffffff; color: black;"&gt;    bingMapsService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateARoute&lt;span style="color: #808030;"&gt;(&lt;/span&gt;criterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;DisplayRoute&lt;span style="color: #808030;"&gt;,&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;FailedRoute&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This event handler is used for the following UI. This is a very simple UI, allows you to enter 2 locations and click calculate. If successful it displays the high level information about the route and then inserts the complete itinerary into a list box.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-zgDkprfWUaY/ToRQ5zHn19I/AAAAAAAAAJc/eLdV2orAWVk/s1600/route+search.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-zgDkprfWUaY/ToRQ5zHn19I/AAAAAAAAAJc/eLdV2orAWVk/s1600/route+search.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The DisplayRoute method is the Rx (reactive extensions) subscriber method, this does the binding of the results to the UI and is shown below:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; DisplayRoute&lt;span style="color: #808030;"&gt;(&lt;/span&gt;RouteSearchResult result&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;resultStatus&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Response: {0} - {1}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;StatusCode&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;StatusDescription&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;HasSucceeded&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;resultDistance&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Distance: {0} {1}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TravelDistance&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;DistanceUnit&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;resultDuration&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Duration: {0} {1}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;TravelDuration&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;DurationUnit&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;resultRouteLegs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Iternary Count: {0}&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;RouteLegs&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ItineraryItems&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;routeLegs&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ItemsSource &lt;span style="color: #808030;"&gt;=&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;RouteLegs&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I'm not going to go any further with examples of how to use the parameters you can specify with the Criterion Factory - hopefully they should be self&amp;nbsp;explanatory.&lt;br /&gt;&lt;br /&gt;What I am going to show is a real world example of where &lt;a href="http://blogs.xamlninja.com/"&gt;Rich&lt;/a&gt;&amp;nbsp;&amp;amp; I are using the route search. This app is currently awaiting certification and therefore we don't want to release the name at the moment, hence the big black marks across the&amp;nbsp;screen shots. The app uses the route search to find a route between 2 exact geo-locations. This is then overlaid as a set of pins and route line on the Bing Maps control. What is interesting with the results is the difference in total distance for each route - both routes start and end at the same locations but the difference is mode of travel. The left screenshot is by car and the right by foot.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Nc_6xFgw9xY/ToRUjBjvXvI/AAAAAAAAAJg/Spw9AT5T-6E/s1600/route+search+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-Nc_6xFgw9xY/ToRUjBjvXvI/AAAAAAAAAJg/Spw9AT5T-6E/s1600/route+search+2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As you can see from the code snippet below, we use the Criterion Factory and Bing Maps Wrapper service in exactly the same manner as the demo. Except this time we are specifying the Waypoints as exact geo-locations, the mode of travel and the distance units.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; CalculateRoute&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoCoordinate geoCoordinate&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var waypoints &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; List&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;WayPoint&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; WayPoint &lt;span style="color: purple;"&gt;{&lt;/span&gt;Point &lt;span style="color: #808030;"&gt;=&lt;/span&gt; geoCoordinate&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; WayPoint &lt;span style="color: purple;"&gt;{&lt;/span&gt;Point &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CurrentlySelectedProperty&lt;span style="color: #808030;"&gt;.&lt;/span&gt;GeoCoordinate&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var distanceUnit &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;settings&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CurrentlySelectedCountry&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsMetric ? DistanceUnit&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Kilometer &lt;span style="color: #808030;"&gt;:&lt;/span&gt; DistanceUnit&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Mile&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    var modeOfTravel &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;IsCarRoute ? ModeOfTravel&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Driving &lt;span style="color: #808030;"&gt;:&lt;/span&gt; ModeOfTravel&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Walking&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    var criterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; CriterionFactory&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CreateRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;waypoints&lt;span style="color: #808030;"&gt;,&lt;/span&gt; modeOfTravel&lt;span style="color: #808030;"&gt;,&lt;/span&gt; distanceUnit&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Optimize&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Time&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;bingMapService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CalculateARoute&lt;span style="color: #808030;"&gt;(&lt;/span&gt;criterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ProcessResponse&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                   exception &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;FailedBingRouteSearch&lt;span style="color: #808030;"&gt;(&lt;/span&gt;exception&lt;span style="color: #808030;"&gt;,&lt;/span&gt; geoCoordinate&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                   &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;CompletedBingRouteSearch&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you want to use the demo you can, it can found in the WP7Contrib Spikes in the 'BingMaps_CriterionFactory' directory. You'll have to have a Bing AppID to use the service &amp;amp; demo, you can register &lt;a href="http://msdn.microsoft.com/en-us/library/ff428642.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-8936884770333538344?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/8936884770333538344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/09/wp7contrib-criterion-factory-route.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8936884770333538344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/8936884770333538344'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/09/wp7contrib-criterion-factory-route.html' title='WP7Contrib: Criterion Factory - calculating a Route'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-zgDkprfWUaY/ToRQ5zHn19I/AAAAAAAAAJc/eLdV2orAWVk/s72-c/route+search.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-2002244378806504130</id><published>2011-09-27T13:28:00.000-07:00</published><updated>2011-09-28T05:25:11.499-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7Contrib WP7 Geo-Location development C#'/><title type='text'>Geo-location on WP7 - don't trust the first value returned</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;a href="http://blogs.xamlninja.com/"&gt;Rich&lt;/a&gt; &amp;amp; I have been working on app which makes heavy use of geo-location information provided by the GeoCoordinateWatcher class on the WP7 platform. As the documentation on &lt;a href="http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinatewatcher(v=VS.92).aspx"&gt;MSDN&lt;/a&gt; states this class exposes the Windows Phone location services. The&amp;nbsp;GeoCoordinateWatcher class implements the&amp;nbsp;INotifyPropertyChanged interface and all the events generated will be fired on the UI thread allowing you to easily bind the class to the UI, but as we already knew this is not always a good idea - for a detailed reason why this can be a bad idea check out this &lt;a href="http://blogs.msdn.com/b/jaimer/archive/2010/11/11/geocoordinatewatcher-tips-part1.aspx"&gt;post&lt;/a&gt; by&amp;nbsp;Jaime Rodriguez.&lt;br /&gt;&lt;br /&gt;What we also discovered is that you can't always trust the first position event generated by this class.&lt;br /&gt;&lt;br /&gt;We have a requirement to get the current location when a user clicks a button, the user could do this at any time when using the application - they could click once, a dozen times or not at all. Every time they click the button we need to get an &lt;b&gt;accurate single value&lt;/b&gt;. The accuracy of the value depend on both the actual value and the age of the value.&amp;nbsp;Every value generated by the&amp;nbsp;GeoCoordinateWatcher class is published by via the&amp;nbsp;PositionChanged event and this is made up of 2 components - the location value and the timestamp when the location value was generated, this is exposed as the&amp;nbsp;GeoPosition&amp;lt;T&amp;gt; class.&lt;br /&gt;&lt;br /&gt;The PositionChanged event is defined as follows. I've included the StatusChanged event to show all the event signatures for the class:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: monospace; white-space: pre;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; GeoCoordinateWatcher &lt;span style="color: #808030;"&gt;:&lt;/span&gt; IDisposable&lt;span style="color: #808030;"&gt;,&lt;/span&gt; INotifyPropertyChanged&lt;span style="color: #808030;"&gt;,&lt;/span&gt; IGeoPositionWatcher&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;event&lt;/span&gt; EventHandler&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoPositionChangedEventArgs&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoCoordinate&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; PositionChanged&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;event&lt;/span&gt; EventHandler&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;GeoPositionStatusChangedEventArgs&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; StatusChanged&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The point of interest is the type used with the event handler. The GeoPositionChangedEventArgs&amp;nbsp;&lt;geocoordinate&gt;class has the following definition.The Position property exposing the GeoPosition&amp;lt;T&amp;gt; value, this has the time stamp value.&lt;/geocoordinate&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; GeoPositionChangedEventArgs&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;T&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #808030;"&gt;:&lt;/span&gt; EventArgs&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; GeoPositionChangedEventArgs&lt;span style="color: #808030;"&gt;(&lt;/span&gt;GeoPosition&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;T&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; position&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; GeoPosition&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;T&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; Position &lt;span style="color: purple;"&gt;{&lt;/span&gt; get&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: monospace; white-space: pre;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;class&lt;/span&gt; GeoPosition&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;T&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: purple; font-family: monospace; white-space: pre;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;"&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; GeoPosition&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; GeoPosition&lt;span style="color: #808030;"&gt;(&lt;/span&gt;DateTimeOffset timestamp&lt;span style="color: #808030;"&gt;,&lt;/span&gt; T position&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; T Location &lt;span style="color: purple;"&gt;{&lt;/span&gt; get&lt;span style="color: purple;"&gt;;&lt;/span&gt; set&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;public&lt;/span&gt; DateTimeOffset Timestamp &lt;span style="color: purple;"&gt;{&lt;/span&gt; get&lt;span style="color: purple;"&gt;;&lt;/span&gt; set&lt;span style="color: purple;"&gt;;&lt;/span&gt; &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We use the following code to return a single geo-location value when the button is clicked. It uses Rx (reactive extensions) to wrap up the call to the&amp;nbsp;GeoCoordinateWatcher class. We don't just use the 'FromEventPattern' Rx method because we don't want the instance of the&amp;nbsp;GeoCoordinateWatcher running riot and generating a gazillion location results and killing the UI thread!&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Eca4i3qBVg0/ToIfwvHVWUI/AAAAAAAAAJE/-esmtss5ce0/s1600/geo-location.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-Eca4i3qBVg0/ToIfwvHVWUI/AAAAAAAAAJE/-esmtss5ce0/s1600/geo-location.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The highlighted areas show how I am using the time offset to determine the validity of the location published by the&amp;nbsp;GeoCoordinateWatcher class. In this demo instance I am saying - &lt;i&gt;'if the position timestamp is greater than 20 seconds ago then ignore the value...'.&amp;nbsp;&lt;/i&gt;When valid the new location is published using the Rx method 'OnNext' on the returned Subject&amp;lt;T&amp;gt;. We also call the Rx 'OnCompleted' method to make the 'Finally' method execute and shut down the watcher by calling 'watcher.Stop()'.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: We also do the 'Start' of the&amp;nbsp;GeoCoordinateWatcher &amp;nbsp;on a background thread to prevent blocking of the current thread - in this case the &lt;a href="http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinatewatcher.trystart.aspx"&gt;UI thread&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This class is the used in the page class as follows:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-dhRFGTVUuvM/ToIkdtfkuxI/AAAAAAAAAJQ/mk86bxYEl_Y/s1600/geo-location3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-dhRFGTVUuvM/ToIkdtfkuxI/AAAAAAAAAJQ/mk86bxYEl_Y/s1600/geo-location3.png" /&gt;&lt;/a&gt;&lt;/div&gt;When run for the first time (on the emulator) I get the following in the output window of visual studio:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-GCdk3O2R78c/ToIjt3JSXZI/AAAAAAAAAJM/-2G12YLIhWg/s1600/geo-location2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-GCdk3O2R78c/ToIjt3JSXZI/AAAAAAAAAJM/-2G12YLIhWg/s1600/geo-location2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;When this is run for subsequent times the debug statements in the output window of visual studio depend on how long the interval between clicking the button.&lt;br /&gt;&lt;br /&gt;The following shows 2 values because the time interval between clicks is greater than 20 seconds. The first value generated by the instance of the GeoCoordinateWatcher class is ignored.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-estYRcOemxo/ToIl1elIw3I/AAAAAAAAAJU/3pVzyQwpfy8/s1600/geo-location4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-estYRcOemxo/ToIl1elIw3I/AAAAAAAAAJU/3pVzyQwpfy8/s1600/geo-location4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;To show this is not an attribute of the currently executing application session, I've added an explicit finalise to the main page as well as a debug statement in the constructor. This shows that once the location services are initialised on the phone and the current location is requested then the last value is always stored by the device and published as the first event when the&amp;nbsp;GeoCoordinateWatcher is started.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-qRvjMhiwo78/ToIrgEwGJXI/AAAAAAAAAJY/Dcc1oTDl3MQ/s1600/geo-location5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-qRvjMhiwo78/ToIrgEwGJXI/AAAAAAAAAJY/Dcc1oTDl3MQ/s1600/geo-location5.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The above screen shot shows 3 distinct&amp;nbsp;activations&amp;nbsp;of the application after tomb-stoning the device twice.&lt;br /&gt;&lt;br /&gt;As you can see the first run shows the last geo-location generated by the device was 4 hours prior, then we tomb-stoned the app for 30 seconds, then re-activated the app with a back press. Again because the previous geo-location was generated greater than 20 seconds ago it is ignored. Finally the last activation after tomb stoning was not greater than 20 seconds so it was not ignored.&lt;br /&gt;&lt;br /&gt;This code has been incorporated into the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib&lt;/a&gt;&amp;nbsp;as the LocationService. It has method for getting the geo-location using time &amp;amp; distance thresholds as well. It also has provides the&amp;nbsp;GeoCoordinateWatcher &amp;nbsp;Status event as an observable method.&lt;br /&gt;&lt;br /&gt;The code is available in this &lt;a href="http://wp7contrib.codeplex.com/SourceControl/changeset/changes/70069"&gt;change-set&lt;/a&gt; or will be part of the 1.4 release due at the end of the month.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559668977390861004-2002244378806504130?l=awkwardcoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://awkwardcoder.blogspot.com/feeds/2002244378806504130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://awkwardcoder.blogspot.com/2011/09/geo-location-on-wp7-dont-trust-first.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/2002244378806504130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559668977390861004/posts/default/2002244378806504130'/><link rel='alternate' type='text/html' href='http://awkwardcoder.blogspot.com/2011/09/geo-location-on-wp7-dont-trust-first.html' title='Geo-location on WP7 - don&apos;t trust the first value returned'/><author><name>Awkward Coder...</name><uri>http://www.blogger.com/profile/09746266491429238639</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6PG1iVEhysY/SroWnkdZ7cI/AAAAAAAAAAg/JE8guIJir6k/s1600-R/60de853ea15dc7270c7bb3b609396c86%3Fs%3D80'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-Eca4i3qBVg0/ToIfwvHVWUI/AAAAAAAAAJE/-esmtss5ce0/s72-c/geo-location.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559668977390861004.post-7843522988207000864</id><published>2011-09-23T09:11:00.000-07:00</published><updated>2011-11-24T06:46:47.993-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7 Bing Maps Development UK Crime'/><title type='text'>How many pins can Bing Maps handle in a WP7 app - part 1</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;part2 -&amp;nbsp;&lt;a href="http://awkwardcoder.blogspot.com/2011/10/how-many-pins-can-bing-maps-handle-in.html"&gt;http://awkwardcoder.blogspot.com/2011/10/how-many-pins-can-bing-maps-handle-in.html&lt;/a&gt;&lt;br /&gt;part3 -&amp;nbsp;&lt;a href="http://awkwardcoder.blogspot.com/2011/11/how-many-pins-can-bing-maps-handle-in.html"&gt;http://awkwardcoder.blogspot.com/2011/11/how-many-pins-can-bing-maps-handle-in.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.xamlninja.com/"&gt;Rich &lt;/a&gt;&amp;amp; I've been working on a WP7 app recently which annotates the Bing Maps control with push pins. These pins represent a point of interest - a reported crime. We've been using the UK crime stats which are provided free of charge, all you have to do is register for an account &lt;a href="http://www.police.uk/api/docs/"&gt;here&lt;/a&gt;. They expose the data using a RESTful service which exposes the data as JSON over HTTP GET requests. It was relatively easy to build a service layer to consume and map this data into a set of model classes for binding to a UI. The RESTful service has multiple endpoints, some are designed to build complex queries spanning multiple HTTP requests and others are single requests based around your current location. The later is what I'll be using for this post.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The API I'm using is the 'street-level crime' endpoint, detailed &lt;a href="http://www.police.uk/api/docs/method/crime-street/"&gt;here&lt;/a&gt;. It provides all crimes that have occurred in a 1 mile radius of a geo-location and does not&amp;nbsp;guarantee&amp;nbsp;accuracy of crime locations.&amp;nbsp;An example URL is shown below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=51.5565555035054&amp;amp;lng=-0.0768184661865234"&gt;http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=51.5565555035054&amp;amp;lng=-0.0768184661865234&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The data returned is&amp;nbsp;truly&amp;nbsp;dynamic - I have no idea how many results will be returned for a geo-location, the amount will vary over time as well as geo-location.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My first task was to get this working and returning data, I wasn't binding the data to the UI at this stage only making sure data was being returned. Shown below is the high level code I used.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--l7qyzcTEeo/Tns5L4_jE9I/AAAAAAAAAH4/FrGIK4vHqWc/s1600/pushpins1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/--l7qyzcTEeo/Tns5L4_jE9I/AAAAAAAAAH4/FrGIK4vHqWc/s1600/pushpins1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;The code snippet is the constructor for the page class and an event handler for the map control.&amp;nbsp;The highlighted area shows how I get the data, when ever the view has finished changing the event handler is called and we then request the crime data. You can see from the second&amp;nbsp;highlighted&amp;nbsp;area the service request, it uses Rx (reactive extensions) to handle the asynchronous nature of making a request over the internet. The result count (the crime count) is written out to a log. The log happens to write out to the debug output and is shown below along with the app.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-PtqPepZBulA/TntEOUmrz5I/AAAAAAAAAIA/KivyZCURqOc/s1600/pushpins2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-PtqPepZBulA/TntEOUmrz5I/AAAAAAAAAIA/KivyZCURqOc/s1600/pushpins2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;As you can see the crime count for the 1 mile radius around the geo-location (51.556555, -0.0768184) is &lt;b&gt;1695&lt;/b&gt;!&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-R2QUtrXAvwk/TntFHuVLUgI/AAAAAAAAAIE/gZbeLHmRnjg/s1600/pushpins3.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-R2QUtrXAvwk/TntFHuVLUgI/AAAAAAAAAIE/gZbeLHmRnjg/s640/pushpins3.png" width="343" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Baseline memory&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The UI for this version consists of a Bing Maps control with a couple of text boxes at the bottom showing the peak and current memory.&amp;nbsp;These are updated regularly (&amp;lt; 250 ms) using a DispatcherTimer class and querying the device extended properties for current and peak memory usage.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The screenshot shown on the left has values of around 21.12&amp;nbsp;Mb&amp;nbsp;- the baseline the map control needs to show a map centred on the above location without panning\zooming the map control.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The next stage was to overlay the push pins and see what happens. I started with overlaying all the returned crime data in one go - iterating over the returned data and adding to the&amp;nbsp;MapItemsControl class. This class was defined in the XAML as shown below, an item template was then applied to the class to get the pin to render. We use a converter to parse the crime category and give it a different colour.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/--whiF_DqBDg/TntJa6EwdqI/AAAAAAAAAII/Pc5-vuUqod4/s1600/pushpins4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/--whiF_DqBDg/TntJa6EwdqI/AAAAAAAAAII/Pc5-vuUqod4/s1600/pushpins4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-cn8y8FvnT6g/TntKrPnPioI/AAAAAAAAAIQ/Qfp7VkWR4bY/s1600/pushpins5.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-cn8y8FvnT6g/TntKrPnPioI/AAAAAAAAAIQ/Qfp7VkWR4bY/s640/pushpins5.png" width="342" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;All 1695 pins&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You'll notice straight away problems with this approach.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Firstly&lt;/b&gt; I can't use the map whilst its adding the pins, the app freezes and does not response to any input. IT takes over 20 seconds from&amp;nbsp;receiving&amp;nbsp;the response from the RESTful service to the pins being shown and the app being&amp;nbsp;usable&amp;nbsp;again. This is a symptom of trying to show to much information to the user and all it will do is confuse and give the perception of a bad user experience. This is in part due to the location where the search was done and&amp;nbsp;the resolution of the map control (zoom = 16).&lt;br /&gt;&lt;br /&gt;Shown below is the debug output and the highlighted lines show the time taken to add the pins to the map control - over 20 seconds.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-8N7vBxhHr1M/TnuKtot4q8I/AAAAAAAAAIs/WcRJyX6iRt0/s1600/pushpins10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-8N7vBxhHr1M/TnuKtot4q8I/AAAAAAAAAIs/WcRJyX6iRt0/s1600/pushpins10.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Secondly&lt;/b&gt; the memory usage has jumped a whopping 53&amp;nbsp;Mb! Its well on its way to the 90&amp;nbsp;Mb&amp;nbsp;limit. Imagine if this page was part of a large app, I can easily see this causing the app to surpass the 90&amp;nbsp;Mb&amp;nbsp;limit.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is due to the fact we are only observing a fraction of the pins added to the map control - the view port is only showing a subset of the available data. I could see them all by zooming out but the following graphics represents the problem perfectly - the pins are being added to the map control even though they are not currently being displayed.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/-m5yn6WqmxcI/TntjK-WJFAI/AAAAAAAAAIU/tczkzJxCt_M/s1600/pushpins6a.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-m5yn6WqmxcI/TntjK-WJFAI/AAAAAAAAAIU/tczkzJxCt_M/s1600/pushpins6a.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Thirdly&lt;/b&gt; every time you scroll the map control it will make another request for data. This in its self is not the problem, its the frequency of the firing of the ViewChangeEnd event. Every time I lift my finger off the screen after scrolling the event would fire, so if I want to scroll more than once the event would fire multiple times. The debug output shows multiple requests being made simultaneously and this is not what we want:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-fcmMn7kN91Y/Tnts5aXUcwI/AAAAAAAAAIY/k4A-GBVdBg4/s1600/pushpins7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-fcmMn7kN91Y/Tnts5aXUcwI/AAAAAAAAAIY/k4A-GBVdBg4/s1600/pushpins7.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A side effect of multiple requests to the RESTful service is the memory usage for the device&amp;nbsp;rockets!&amp;nbsp;Its easy to get the value above 200 Mb and eventually you'll get an OutOfMemory exception.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Zh97d2ZBmmo/TntxelI7jII/AAAAAAAAAIg/6dqoY2XSMK8/s1600/pushpins8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-Zh97d2ZBmmo/TntxelI7jII/AAAAAAAAAIg/6dqoY2XSMK8/s1600/pushpins8.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;And Fourthly&lt;/b&gt; when adding pins to the&amp;nbsp;MapItemsControl class it only checks if a pins exists using reference equality, therefore if you have to&amp;nbsp;separate&amp;nbsp;instances for the same pin then it will be added twice to the map control. I suspect this is causing the majority of the memory allocation shown above.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Tackling the third &amp;amp; fourth problems first I should be able to reduce the memory usage and provide good code for future versions of the code base.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The first task was to deal with&amp;nbsp;multiple&amp;nbsp;requests happening at the same time. This is done by cancelling any currently executing request and then starting the new request. This was easy to do because we are using Rx. All we have to do is dispose of the current subscriber ( 'currentSubscriber') and initiate a new request.&lt;br /&gt;&lt;br /&gt;Shown below is the modified code, it has the null check and explicit dispose of the 'currentSubscriber' variable before the assigment of the new subscriber.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;void&lt;/span&gt; HandleViewChangeEnd&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;object&lt;/span&gt; sender&lt;span style="color: #808030;"&gt;,&lt;/span&gt; MapEventArgs mapEventArgs&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    var criterion &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;new&lt;/span&gt; StreetLevelCrimeCriterion &lt;span style="color: purple;"&gt;{&lt;/span&gt; Latitude &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;map&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; Longitude &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;map&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Center&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Started - ({0}, {1})&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;b&gt;  &lt;span style="color: maroon;"&gt;if&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeSubscriber &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;null&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: maroon;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeSubscriber&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Dispose&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;    &lt;b&gt;&lt;span style="color: maroon;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeSubscriber&lt;/b&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;crimeService&lt;span style="color: #808030;"&gt;.&lt;/span&gt;SearchCrimeRelatedStreetLevelCrime&lt;span style="color: #808030;"&gt;(&lt;/span&gt;criterion&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;ObserveOnDispatcher&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #808030;"&gt;.&lt;/span&gt;Subscribe&lt;span style="color: #808030;"&gt;(&lt;/span&gt;result &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Crime count = {0}, ({1}, {2})&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Crimes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                            &lt;span style="color: maroon; font-weight: bold;"&gt;foreach&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var crime &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Crimes&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;                                &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;                            &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                    exception &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Exception, message - '{0}'&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; exception&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Message&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;log&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Write&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;string&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Format&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Completed - ({0}, {1})&lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude&lt;span style="color: #808030;"&gt;,&lt;/span&gt; criterion&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;Now when the code executes I see something&amp;nbsp;similar&amp;nbsp;to below. It shows 5 requests being made simultaneously but only 1 set of results being processed and the results being process are the result from the last request. You will also notice the highlighted screenshot of the device emulator - the memory consumption is&amp;nbsp;considerably&amp;nbsp;less then 200 Mb, still not perfect but better.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OfEYmYrBm4g/Tnt3n9UxjkI/AAAAAAAAAIo/Dctk4vcR5Zg/s1600/pushpins9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-OfEYmYrBm4g/Tnt3n9UxjkI/AAAAAAAAAIo/Dctk4vcR5Zg/s1600/pushpins9.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;Next to address is&amp;nbsp;multiple&amp;nbsp;pins for the same location. As I said it appears the&amp;nbsp;MapItemsControl class uses reference equality to check for multiple pins and since there are multiple instances for the same location all I need to do is filter any existing before adding. This is done with a LINQ query:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;foreach&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var crime &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Crimes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Where&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #808030;"&gt;!&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Cast&lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;StreetLevelCrime&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Any&lt;span style="color: #808030;"&gt;(&lt;/span&gt;c &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; c&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Id &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; crime&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Id&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;count&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Pin count - &lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div&gt;The screenshot below shows 3 requests being made to the RESTful service. The aggregated pin count would be 5172 (1695 + 1809 + 1668) without the above code but as you can see from the highlighted emulator device the actual pin count is 2245.&lt;br /&gt;&lt;br /&gt;The memory usage is still not acceptable, we are not seeing memory usage around the 200 Mb any more but 90Mb is still too much.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-r67sqc9n4Fs/TnuO1sh5n5I/AAAAAAAAAIw/Kt12PuXqoL8/s1600/pushpins11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-r67sqc9n4Fs/TnuO1sh5n5I/AAAAAAAAAIw/Kt12PuXqoL8/s1600/pushpins11.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I can now address the first and second problems - the time taken to add pins and the amount of memory consumed. To tackle these issues we are going to have to reduce the number of pins on the map control.&lt;br /&gt;&lt;br /&gt;The simplest way to do this is to only add the pins required to be shown to the collection of the&amp;nbsp;MapItemsControl &amp;nbsp;class. This is&amp;nbsp;achieved&amp;nbsp;by taking the current viewable bounding rectangle of the map control and only adding pins which fall inside this rectangle.&amp;nbsp;This does require the removing of any existing pins added to the collection which do not fall inside the viewable bounding rectangle. The bounding rectangle is expressed as a LocationRect class which is a set of geo-locations - north, west, east, south. All I have to do is calculate if a pins fall inside this bounding rectangle. To do this I have updated the LINQ query:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;var rectangle &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;map&lt;span style="color: #808030;"&gt;.&lt;/span&gt;BoundingRectangle&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Clear&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;foreach&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;var crime &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; result&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Crimes&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Where&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime &lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Location&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; rectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;North&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &amp;amp;&amp;amp;&lt;br /&gt;                                        &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Location&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Latitude &lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; rectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;South&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &amp;amp;&amp;amp;&lt;br /&gt;                                        &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Location&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude &lt;span style="color: #808030;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; rectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;West&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &amp;amp;&amp;amp;&lt;br /&gt;                                        &lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Location&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Longitude &lt;span style="color: #808030;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; rectangle&lt;span style="color: #808030;"&gt;.&lt;/span&gt;East&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Add&lt;span style="color: #808030;"&gt;(&lt;/span&gt;crime&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: purple;"&gt;}&lt;/span&gt;&lt;br /&gt;                                   &lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;count&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Text &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: maroon;"&gt;"&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;Pin count - &lt;/span&gt;&lt;span style="color: maroon;"&gt;"&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: maroon; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #808030;"&gt;.&lt;/span&gt;MapPins&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Items&lt;span style="color: #808030;"&gt;.&lt;/span&gt;Count&lt;span style="color: purple;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can now see from the screenshot below the pin count has greatly reduced to between 110 - 240 and more importantly the memory usage is at a more acceptable level. In fact the peak memory usage is now only 61.86 Mb.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-j_CtTQIQa-w/TnxcTfTY19I/AAAAAAAAAI0/P-HrfcQ-O84/s1600/pushpins12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-j_CtTQIQa-w/TnxcTfTY19I/AAAAAAAAAI0/P-HrfcQ-O84/s1600/pushpins12.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;This is now approaching a usable solution, but there a couple issues still affecting the UI. Firstly the updating of the map is not very fluid, in fact its rather jumpy - when the new pins are added they suddenly appear on the map without warning and there isn't any 
