<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# &#8211; James Lin&#039;s Blog</title>
	<atom:link href="https://james.lin.net.nz/category/technology/programming/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>https://james.lin.net.nz</link>
	<description>Just bits and pieces of my life</description>
	<lastBuildDate>Fri, 19 Jan 2018 22:42:50 +0000</lastBuildDate>
	<language>en-NZ</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.2</generator>
<site xmlns="com-wordpress:feed-additions:1">22801464</site>	<item>
		<title>Bitwise and Enum</title>
		<link>https://james.lin.net.nz/2011/07/13/bitwise-and-enum/</link>
		<comments>https://james.lin.net.nz/2011/07/13/bitwise-and-enum/#respond</comments>
		<pubDate>Wed, 13 Jul 2011 08:23:23 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=674</guid>
		<description><![CDATA[It&#8217;s been so long that I haven&#8217;t touched C# and today I got the chance to use it again, as you know, Enum is kind of popular in C# and for sure I encountered the bitwise operation again. To quickly pick it up again, I came across this awesome article http://weblogs.asp.net/wim/archive/2004/04/07/109095.aspx]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been so long that I haven&#8217;t touched C# and today I got the chance to use it again, as you know, Enum is kind of popular in C# and for sure I encountered the bitwise operation again.</p>
<p>To quickly pick it up again, I came across this awesome article <a href="http://weblogs.asp.net/wim/archive/2004/04/07/109095.aspx">http://weblogs.asp.net/wim/archive/2004/04/07/109095.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2011/07/13/bitwise-and-enum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">674</post-id>	</item>
		<item>
		<title>Where AM I? An offline google map application.</title>
		<link>https://james.lin.net.nz/2010/07/28/where-am-i-an-offline-google-map-application/</link>
		<comments>https://james.lin.net.nz/2010/07/28/where-am-i-an-offline-google-map-application/#respond</comments>
		<pubDate>Wed, 28 Jul 2010 01:09:34 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://james-lin.no-ip.org/?p=13</guid>
		<description><![CDATA[Disclaimer: This article is for educational purpose only, it is purely demonstrating how google map works. Hi Guys, If you are reading this article, you should know about google maps. It&#8217;s an awesome service, and the API provided can help you to do lots stuff, ie inputting your GPS coordinates and pin point where you are.… <span class="read-more"><a href="https://james.lin.net.nz/2010/07/28/where-am-i-an-offline-google-map-application/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<div>Disclaimer:</div>
<div>This article is for educational purpose only, it is purely demonstrating how google map works.</div>
<div>Hi Guys,</div>
<div>If you are reading this article, you should know about google maps.  It&#8217;s an awesome service, and the API provided can help you to do lots  stuff, ie inputting your GPS coordinates and pin point where you are.  HOWEVER, google maps only works when you have an internet connection,  which is not feasible for most of us to have wireless internet card.</div>
<div>So I started to think, what if I can store google map on to my harddrive??</div>
<div>Then I searched and searched and searched on google&#8230; finally I found 2 links that helped me achieve this.</div>
<div>The first link which helped me how to retrieve the map:</div>
<div><a href="http://www.codeproject.com/KB/scrapbook/googlemap.aspx">http://www.codeproject.com/KB/scrapbook/googlemap.aspx</a></div>
<div>The second link which helped me to find out where I am exactly:</div>
<div><a href="http://discussion.forum.nokia.com/forum/showthread.php?t=124532">http://discussion.forum.nokia.com/forum/showthread.php?t=124532</a></div>
<div>Let me briefly put them together</div>
<ol>
<li>You need to find out the GPS boundaries for your city, left upper bound and bottom right bound.</li>
<li>Use the c# function getTileXY(double lat, double lon, int zoom)  provided below to calculate the X,Y tile coordinates to help you  &#8220;retrieve&#8221; the maps from google map. Eg. left upper bound tile is x=10,  y=10 and bottom right bound tile is x=100, y=100, then you use a for  loop to download the tiles in between those 2 bounds, x=11,  y=10&#8230;&#8230;x=99, y=98&#8230;.</li>
<li>Now, assume you have &#8220;retrieved&#8221; all the map tiles for your  city, use the same c# function getTileXY(double lat, double lon, int  zoom) which work out the x,y tile to find out which tile you are  currently at.</li>
<li>After finding the tile you are currently at, ie. x=55, y=67  tile, you need to work out the pixel coordinate inside a tile to pin  point where you are inside a tile, use C# function  getXYPixelFromTile(double lat, double lon, int zoom)</li>
</ol>
<p>A Map Tile looks like this:</p>
<p><a href="http://blufiles.storage.live.com/y1p9RDN5ritpUS1ZN4CZnIjN1xNddJF7h3559yur_2aQqhEssSWTJfWGgSKwnUrgavI_mx2YgL0VPg"><img src="http://blufiles.storage.live.com/y1p9RDN5ritpUS1ZN4CZnIjN1xNddJF7h3559yur_2aQqhEssSWTJfWGgSKwnUrgavI_mx2YgL0VPg" alt="2017-1249-6" width="128" height="128" /></a></p>
<p>OK, thats the theory, you should be able to build up an application hooks up to a GPS device:</p>
<p><a href="http://blufiles.storage.live.com/y1p9RDN5ritpUSYRFZYsDCH2t1Pbt83Z6UPrWUIoqnQ2KzcjgLBnCIhWnP8hE-NqhrpPUo2oVIA2aE"><img src="http://blufiles.storage.live.com/y1p9RDN5ritpUSYRFZYsDCH2t1Pbt83Z6UPrWUIoqnQ2KzcjgLBnCIhWnP8hE-NqhrpPUo2oVIA2aE" alt="GPS" width="300" height="176" /></a></p>
<p>C# Functions:</p>
<p></p><pre class="crayon-plain-tag">public static Point getTileXY(double lat, double lon, int zoom)
{
/* Per se earth coordinates are -90?&amp;lt;= lat &amp;lt;= +90?and -180?&amp;lt;= lon &amp;lt;= 180?*/
/* Mercator is NOT applicable for abs(lat) &amp;gt; 85.0511287798066 degrees */
if (System.Math.Abs(lat) &amp;gt; 85.0511287798066)
return new Point(0, 0);
/* latitude (deg) -&amp;gt; latitude (rad) */
double sin_phi = System.Math.Sin(lat * System.Math.PI / 180);
/*
* Use Mercator to calculate x and normalize this to -1 &amp;lt;= x &amp;lt;= +1 by division by 180.
* The center of the map is lambda_0 = 0, hence x = lat.
*/
double norm_x = lon / 180;
/*
* Use Mercator to calculate y and normalize this to -1 &amp;lt;= y &amp;lt;= +1 by division by PI.
* According to Mercator y is defined in the range of -PI &amp;lt;= y &amp;lt;= PI only
*/
double norm_y = (0.5 * System.Math.Log((1 + sin_phi) / (1 - sin_phi))) / System.Math.PI;
/*
* Apply the normalized point coordinations to any application, here the coordinates of
* a 256*256 image holding that point in a thought grid with origin 0,0 top/left
*/
double tileRow = System.Math.Pow(2, 17 - zoom) * ((1 - norm_y) / 2);
double tileColumn = System.Math.Pow(2, 17 - zoom) * ((norm_x + 1) / 2);
return new Point((int)tileColumn, (int)tileRow);
}

public static Point getXYPixelFromTile(double lat, double lon, int zoom)
{
/* Per se earth coordinates are -90?&amp;lt;= lat &amp;lt;= +90?and -180?&amp;lt;= lon &amp;lt;= 180?*/
/* Mercator is NOT applicable for abs(lat) &amp;gt; 85.0511287798066 degrees */
if (System.Math.Abs(lat) &amp;gt; 85.0511287798066)
return new Point(0, 0);
/* latitude (deg) -&amp;gt; latitude (rad) */
double sin_phi = System.Math.Sin(lat * System.Math.PI / 180);
/*
* Use Mercator to calculate x and normalize this to -1 &amp;lt;= x &amp;lt;= +1 by division by 180.
* The center of the map is lambda_0 = 0, hence x = lat.
*/
double norm_x = lon / 180;
/*
* Use Mercator to calculate y and normalize this to -1 &amp;lt;= y &amp;lt;= +1 by division by PI.
* According to Mercator y is defined in the range of -PI &amp;lt;= y &amp;lt;= PI only
*/
double norm_y = (0.5 * System.Math.Log((1 + sin_phi) / (1 - sin_phi))) / System.Math.PI;
/*
* Apply the normalized point coordinations to any application, here the coordinates of
* a 256*256 image holding that point in a thought grid with origin 0,0 top/left
*/
double tileRow = System.Math.Pow(2, 17 - zoom) * ((1 - norm_y) / 2);
double tileColumn = System.Math.Pow(2, 17 - zoom) * ((norm_x + 1) / 2);
int y = (int)((tileColumn - (int)tileColumn) * 256);
int x = (int)((tileRow - (int)tileRow) * 256);
Console.Out.WriteLine(x +&quot; &quot; + y);
return new Point(y,x);
}</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2010/07/28/where-am-i-an-offline-google-map-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">13</post-id>	</item>
	</channel>
</rss>
