<?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>Stickblog</title>
	<atom:link href="http://the-stickman.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://the-stickman.com</link>
	<description>Random developer notes</description>
	<lastBuildDate>Fri, 26 Aug 2016 09:00:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>Internet Explorer ignoring cookies&#8230;why?</title>
		<link>http://the-stickman.com/web-development/internet-explorer-ignoring-cookies-why/</link>
		<comments>http://the-stickman.com/web-development/internet-explorer-ignoring-cookies-why/#comments</comments>
		<pubDate>Fri, 26 Aug 2016 08:58:55 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=262</guid>
		<description><![CDATA[Wow, five years since my last post? Anyway&#8230; A short post, although it took me a couple of hours to solve this one&#8230; While working on a local development version of a web site project, I found that for some reason I was unable to log in to my CMS when testing with Internet Explorer. For the life [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Wow, five years since my last post? Anyway&#8230;</p>
<p>A short post, although it took me a couple of hours to solve this one&#8230;</p>
<p>While working on a local development version of a web site project, I found that for some reason I was unable to log in to my CMS when testing with Internet Explorer. For the life of me I couldn&#8217;t work out what was going on &#8212; everything seemed to be working as it should, except that for some reason IE was regenerating its session cookie on every page load.</p>
<p>I tried everything I could think of, to no avail, until I stumbled <a title="StackOverflow" href="https://stackoverflow.com/questions/306132/php-session-doesnt-work-with-ie#answer-306601" target="_blank">this obscure response on StackOverflow</a>. The reason in the end was very simple: IE doesn&#8217;t like underscore characters in domain names (although the answer incorrectly suggests that hyphens are problematic, too).</p>
<p>Fair enough, IE is adhering to the relevant RFC standard but to do so by silently ignoring cookies is just absurd. If it doesn&#8217;t support domain names with this character, surely it should just reject the whole site and give an error (e.g. &#8220;domain name contains illegal characters&#8221;)?</p>
<p><em>Sigh.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/internet-explorer-ignoring-cookies-why/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internet Explorer, HTTPS and file downloads: &#8220;The file could not be written to the cache&#8221;</title>
		<link>http://the-stickman.com/uncategorized/internet-explorer-https-and-file-downloads-the-file-could-not-be-written-to-the-cache/</link>
		<comments>http://the-stickman.com/uncategorized/internet-explorer-https-and-file-downloads-the-file-could-not-be-written-to-the-cache/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 10:53:08 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=257</guid>
		<description><![CDATA[[Please see update below for a proper fix] Today I received an email from a client that had just moved their site over to SSL (i.e. HTTPS) &#8212; they were no longer able to download files in Internet Explorer. When they tried to do so, a message would appear: Unable to download...[file name] The file [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>[Please see update below for a proper fix]</p>
<p>Today I received an email from a client that had just moved their site over to SSL (i.e. HTTPS) &#8212; they were no longer able to download files in Internet Explorer. When they tried to do so, a message would appear:</p>
<p><code>Unable to download...[file name]</code></p>
<p><code>The file could not be written to the cache</code></p>
<p>(an alternative error message is &#8220;Internet Explorer cannot download [file name] from [site].<br />Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.&#8221;)</p>
<p>I tried various suggestions: different response headers, settings to do with saving encrypted files, and even tried (and failed) to install a couple of hotfixes.</p>
<p>In the end, I&#8217;d nearly given up when I found <a href="http://support.microsoft.com/kb/323308" target="_blank">this knowledgebase article</a> and decided to have a go at manually adding the <em>BypassSSLNoCacheCheck</em> registry key.</p>
<p>Short story, it worked. It&#8217;s not great since it requires the user to do something &#8212; I couldn&#8217;t fix it server-side &#8212; but it was OK in this case because the site was an intranet so their IT people could sort it. Anyway, I hope this helps someone else out there&#8230;</p>
<p><strong>UPDATE: </strong>OK, after a lot more experimentation I found a proper solution that doesn&#8217;t involve registry updates!</p>
<p>It&#8217;s a long story but it turns out that PHP was automatically sending an extra header (&#8220;Pragma: no-cache&#8221;) that I hadn&#8217;t noticed. So, I set the headers as follows:</p>
<p><code>header("Cache-Control: private");</code><br /> <code>header( "Pragma: private" );</code></p>
<p>&#8230;which overrides the automated headers and appears to solve the problem. Hurray!</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/uncategorized/internet-explorer-https-and-file-downloads-the-file-could-not-be-written-to-the-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using .htaccess to suspend an entire site while still working on it</title>
		<link>http://the-stickman.com/web-development/using-htaccess-to-suspend-an-entire-site-while-still-working-on-it/</link>
		<comments>http://the-stickman.com/web-development/using-htaccess-to-suspend-an-entire-site-while-still-working-on-it/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 11:02:44 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=244</guid>
		<description><![CDATA[Sometimes, when you&#8217;re working on a web site, you need to make some changes that could cause problems if there is someone else using the site at the time. The obvious solution is to suspend the site &#8212; e.g. put up a &#8216;this site is down for maintenance&#8217; page &#8212; but how do you do [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Sometimes, when you&#8217;re working on a web site, you need to make some changes that could cause problems if there is someone else using the site at the time. The obvious solution is to suspend the site &#8212; e.g. put up a &#8216;this site is down for maintenance&#8217; page &#8212; but how do you do this while still being able to view and work on the site yourself?</p>
<p>In fact, it&#8217;s really quite easy, using .htaccess. Simply put, you use mod_rewrite to redirect all requests to the maintenance page, unless the user&#8217;s browser has a particular cookie.</p>
<p>
<code>RewriteEngine On</code><br/><code>RewriteBase</code><br/><code>RewriteCond %{HTTP_COOKIE} !^.*secret-cookie.*$ [NC]</code><br/><code>RewriteRule .* maintenance-page.html [NC,L,R=503]</code></p>
<p>Clearly you can change the name of the cookie from &#8216;secret-cookie&#8217; to whatever you like. Its value isn&#8217;t important. And of course, you can change the name of your maintenance page.</p>
<p><strong>Update</strong>: as suggested by Michael, below, I&#8217;ve added the R=503 status code to indicate that the service is temporarily unavailable.</p>
<p>Now you just need to create the cookie in your browser. Personally I use the <a title="FireCookie" href="https://addons.mozilla.org/en-us/firefox/addon/firecookie/">FireCookie</a> extension for <a title="Firebug" href="http://getfirebug.com/">Firebug</a> which makes this very easy.</p>
<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/using-htaccess-to-suspend-an-entire-site-while-still-working-on-it/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FireQuery: a Firebug add-on for jQuery</title>
		<link>http://the-stickman.com/web-development/firefox-extensions/firequery-a-firebug-add-on-for-jquery/</link>
		<comments>http://the-stickman.com/web-development/firefox-extensions/firequery-a-firebug-add-on-for-jquery/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 09:49:25 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Firefox Extensions]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=241</guid>
		<description><![CDATA[If you work with jQuery, then I don&#8217;t think I need to explain why a plugin that shows you any jQuery-related properties of a DOM element would be useful &#8212; so go on and get it here. Of course you&#8217;ll need to have installed Firebug first (which you should have anyway, duh).]]></description>
				<content:encoded><![CDATA[<p>If you work with jQuery, then I don&#8217;t think I need to explain why a plugin that shows you any jQuery-related properties of a DOM element would be useful &#8212; so go on and get it <a href="http://firequery.binaryage.com/">here</a>. Of course you&#8217;ll need to have installed <a href="http://getfirebug.com/">Firebug</a> first (which you should have anyway, duh).</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/firefox-extensions/firequery-a-firebug-add-on-for-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating PDFs in PHP</title>
		<link>http://the-stickman.com/web-development/php/generating-pdfs-in-php/</link>
		<comments>http://the-stickman.com/web-development/php/generating-pdfs-in-php/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 12:25:15 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=235</guid>
		<description><![CDATA[For several recent projects I&#8217;ve been called upon to produce output in PDF format. For a PHP coder the difficulty lies not in the task itself, but in choosing which of the numerous PDF generation libraries to use. I&#8217;ve tried several over the past 18 months or so, including FPDF and TCPDF. TCPDF is a direct [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>For several recent projects I&#8217;ve been called upon to produce output in PDF format. For a PHP coder the difficulty lies not in the task itself, but in choosing which of the numerous PDF generation libraries to use.</p>
<p>I&#8217;ve tried several over the past 18 months or so, including <a href="http://www.fpdf.org/">FPDF</a> and <a href="http://www.tcpdf.org/">TCPDF</a>. TCPDF is a direct wrapper for PDF functions, which means getting your head around PDF&#8217;s layout behaviour &#8212; powerful but rather time-consuming. TCPDF does the same but also provides the ability to import HTML documents &#8212; much easier, but unfortunately not as stable as one might hope: in particular I had problems with elements (e.g. tables) that spanned pages.</p>
<p>For my most recent project I&#8217;ve been experimenting with <a href="http://code.google.com/p/dompdf/">dompdf</a>, which does away almost entirely with the notion of directly interacting with PDF layout in favour of attempting to provide more robust and flexible HTML import. As such it has impressively advanced CSS support, as well as excellent handling of tables and other markup. The documentation is somewhat lacking so in some cases it&#8217;s necessary to dig around in the support forum to find out what you need. But so far I&#8217;d say it&#8217;s by some margin the best of the libraries I&#8217;ve tried.</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/php/generating-pdfs-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On redirects, spiders and security</title>
		<link>http://the-stickman.com/web-development/on-redirects-spiders-and-security/</link>
		<comments>http://the-stickman.com/web-development/on-redirects-spiders-and-security/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 14:07:57 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=232</guid>
		<description><![CDATA[Recently I&#8217;ve been working with an agency that has its own simple PHP web site framework. During the course of working with them, a problem arose: pages were disappearing, apparently without human involvement. With some detective work they had discovered that somehow the &#8216;secure&#8217; CMS part of the site &#8212; where the client can log [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;ve been working with an agency that has its own simple PHP web site framework. During the course of working with them, a problem arose: pages were disappearing, apparently without human involvement.</p>
<p>With some detective work they had discovered that somehow the &#8216;secure&#8217; CMS part of the site &#8212; where the client can log in to make changes &#8212; was being crawled by automated search engines. Part of the CMS is a list of all the site&#8217;s pages, each with links to the usual operations &#8212; edit, delete etc.  When the spider was indexing the pages, it also accessed the delete link, thereby deleting the page (much like <a href="http://thedailywtf.com/Articles/The_Spider_of_Doom.aspx">this DailyWTF story</a>).</p>
<p>Oops.</p>
<p>Anyway I took a look and while the security wasn&#8217;t great &#8212; it was based around cookies with no server-side validation &#8212; it still seemed odd that the spiders were able to access the pages. I implemented a slightly more robust system using sessions, added an entry to robots.txt, and marked it as solved.</p>
<p>And then it happened again.</p>
<p>I couldn&#8217;t work out what was going wrong, so to stop it happening I converted all the delete links to forms. But it was nagging at me &#8212; how was it that the search engines were reaching the pages at all? Why weren&#8217;t they being rejected when the security script checked for a cookie and session?</p>
<p>Finally, the penny dropped&#8230;</p>
<p>The security check worked by looking for a valid session, checking it for a &#8216;user is logged in&#8217; value, and if one wasn&#8217;t found then sending a redirect header pointing to the login page. Nothing unusual there. So what was going on?</p>
<p>When PHP sends a redirect header, the browser says &#8220;OK, I&#8217;ll go to this other page&#8221; and the user&#8217;s none the wiser. But just because the browser is no longer listening, that doesn&#8217;t mean the script automatically stops running. In fact, unless you tell it to stop it just continues as if nothing had happened. Thus, the spiders were simply ignoring the header and receiving the page as if there were no security in place at all.</p>
<p>The solution? Add an &#8216;exit;&#8217; after the redirect header. Simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/on-redirects-spiders-and-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web fonts: the time has come</title>
		<link>http://the-stickman.com/web-development/web-fonts-the-time-has-come/</link>
		<comments>http://the-stickman.com/web-development/web-fonts-the-time-has-come/#comments</comments>
		<pubDate>Fri, 28 May 2010 08:48:14 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=226</guid>
		<description><![CDATA[A couple of weeks ago, I spotted a post on Slashdot about a company &#8211; fonts.com &#8211;  that was opening up its font library for use by web developers. I thought it was a pretty neat idea: it uses the new-ish @css-font functionality that works in most modern browsers &#8211; along with a bit of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A couple of weeks ago, I spotted a post on Slashdot about a company &#8211; <a href="http://www.webfonts.fonts.com/">fonts.com</a> &#8211;  that was opening up its font library for use by web developers. I thought it was a pretty neat idea: it uses the new-ish @css-font functionality that works in most modern browsers &#8211; along with a bit of JavaScript magic &#8211; to allow you to, in effect, embed a font in a web page such that it can be used like any other standard font.</p>
<p>No more image replacement, or clunky <a href="http://www.mikeindustries.com/blog/sifr">sIFR</a> nonsense to get pages looking as your clients actually want them to!</p>
<p>After that, I became aware that there&#8217;s more than one web site out there offering similar service. So here&#8217;s a run-down of those I know of &#8212; feel free to add a comment if you know of any that I&#8217;ve missed:</p>
<ul>
<li><a href="http://www.webfonts.fonts.com/">WebFonts</a> &#8211; as mentioned above, over 2,000 fonts to choose from and more on the way.</li>
<li><a href="http://cufon.shoqolate.com/generate/">Cufon</a> &#8211; allows you to upload your own font files and then download them compiled for web use.</li>
<li><a href="http://www.fontsquirrel.com/fontface">FontFace</a> &#8211; download pre-packaged &#8216;kits&#8217; or roll your own.</li>
<li><a href="http://code.google.com/apis/webfonts/">Google Web Fonts</a> &#8211; yes, even the mighty Google is getting in on the act, although the choice is rather limited.</li>
</ul>
<p><strong>Update: </strong>From the comments (thanks!):</p>
<ul>
<li><a href="http://kernest.com/">Kernest</a></li>
<li><a href="http://www.fontslive.com">FontsLive</a></li>
<li><a href="http://www.typekit.com">TypeKit</a><a rel="nofollow" href="http://www.fontslive.com"></a></li>
<li><a href="http://www.typefront.com">TypeFront</a><a rel="nofollow" href="http://www.typekit.com"></a></li>
<li><a href="http://www.fontspring.com">FontSpring</a><a rel="nofollow" href="http://www.typefront.com"></a></li>
<li><a href="http://www.fontdeck.com">FontDeck</a> (closed beta as of this update)<a rel="nofollow" href="http://www.fontspring.com"></a></li>
</ul>
<p>Seems like it&#8217;s a technology whose time has arrived.</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/web-fonts-the-time-has-come/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PayPal Error: Sorry, an Error Occurred After You Clicked the Last Link</title>
		<link>http://the-stickman.com/uncategorized/paypal-error-sorry-an-error-occurred-after-you-clicked-the-last-link/</link>
		<comments>http://the-stickman.com/uncategorized/paypal-error-sorry-an-error-occurred-after-you-clicked-the-last-link/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 15:09:24 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://the-stickman.com/uncategorized/paypal-error-sorry-an-error-occurred-after-you-clicked-the-last-link/</guid>
		<description><![CDATA[I&#8217;m just coming to the end of a project that required checkout via PayPal. The system is to be hosted in an iframe embedded in a third party site&#8217;s page, but when redirecting to PayPal the iframe &#8216;pops out&#8217; to take over the whole page (PayPal forces this behaviour). All was working smoothly using the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m just coming to the end of a project that required checkout via PayPal. The system is to be hosted in an iframe embedded in a third party site&#8217;s page, but when redirecting to PayPal the iframe &#8216;pops out&#8217; to take over the whole page (PayPal forces this behaviour).</p>
<p>All was working smoothly using the &#8216;PayPal sandbox&#8217; testing domain, but when it came to testing a live transaction in Internet Explorer I received the following error:</p>
<p>&#8220;Sorry, an Error Occurred After You Clicked the Last Link&#8221;</p>
<p>&#8230;followed by a lengthy but rather unhelpful block of text suggesting various courses of action &#8212; none of which was any use at all.</p>
<p><a href="http://www.google.co.uk/search?q=paypal+%22Sorry,+an+error+occurred+after+you+clicked+the+last+link%22">Consulting Google</a>, it seems that this is far from an unusual occurrence but there&#8217;s little consensus as to the cause. In the end, I tried adding target=&#8221;_top&#8221; to the form that submits to PayPal (thus forcing the &#8216;pop-out&#8217; of the iframe), and presto, all is now fine again.</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/uncategorized/paypal-error-sorry-an-error-occurred-after-you-clicked-the-last-link/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CSS: Removing that dotted line around a link</title>
		<link>http://the-stickman.com/web-development/css-removing-that-dotted-line-around-a-link/</link>
		<comments>http://the-stickman.com/web-development/css-removing-that-dotted-line-around-a-link/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 09:44:06 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=219</guid>
		<description><![CDATA[Just a quick note to myself&#8230; I&#8217;m working on a navigation system that uses CSS image replacement. To hide the text, CSS shifts it out of view by using the text-indent property and a big negative value. However, a side-effect of this is that when you click on a link, the dotted border that appears [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Just a quick note to myself&#8230;</p>
<p>I&#8217;m working on a navigation system that uses CSS image replacement. To hide the text, CSS shifts it out of view by using the <em>text-indent</em> property and a big negative value. However, a side-effect of this is that when you click on a link, the dotted border that appears while you&#8217;re holding the mouse button down goes off the side of the page.</p>
<p>To get around this, I just wanted to disable it. After some searching I discovered the <em>outline</em> property &#8212; setting this to &#8216;none&#8217; gets rid of it entirely:</p>
<p><code>a{<br />
outline: none;<br />
}</code></p>
<p>Of course, the above will remove it for all links, it&#8217;s up to you to decide whether you want to make it more specific.</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/web-development/css-removing-that-dotted-line-around-a-link/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Converting latitude and longitude coordinates to map x and y values</title>
		<link>http://the-stickman.com/uncategorized/converting-latitude-and-longitude-coordinates-to-map-x-and-y-values/</link>
		<comments>http://the-stickman.com/uncategorized/converting-latitude-and-longitude-coordinates-to-map-x-and-y-values/#comments</comments>
		<pubDate>Tue, 19 May 2009 08:37:18 +0000</pubDate>
		<dc:creator><![CDATA[Stickman]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://the-stickman.com/?p=212</guid>
		<description><![CDATA[I&#8217;m currently working on a project to convert an existing Flash map, which uses location data that&#8217;s been manually entered and maintained, to use data that comes from a database and uses latitude and longitude values. The original data is stored in an XML file so updating it dynamically is not a problem but as [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m currently working on a project to convert an existing Flash map, which uses location data that&#8217;s been manually entered and maintained, to use data that comes from a database and uses latitude and longitude values. The original data is stored in an XML file so updating it dynamically is not a problem but as you&#8217;ll know if you&#8217;ve ever tried it, plotting latitude and longitude values on a map isn&#8217;t as simple as it might sound.</p>
<p>Briefly, the problem arises from the fact that the world is a sphere and representing it in two dimensions is not a straightforward task. There are various &#8216;projections&#8217; to choose from, each of which uses a different method for mapping points &#8212; you can find out more in <a href="http://en.wikipedia.org/wiki/Map_projection">this Wikipedia article</a>. The most common choice is the <a href="http://en.wikipedia.org/wiki/Mercator_projection">Mercator projection</a>, where lines of latitude are spaced equally, and fortunately for me it&#8217;s the type of map used in the project I&#8217;m working on.</p>
<p>So, being somewhat mathematically inept, I decided that Google would save me from a day&#8217;s head-scratching. That turned out not to be the case, as I tried a good half-dozen different suggestions before finally stumbling across one that actually produced accurate results. To save others from the same fate I decided to reproduce here the code I ended up with, which is based heavily on code found in <a href="http://groups.google.com/group/Google-Maps-API/browse_thread/thread/a45947d72c27cc73#d21b6238fae63a7c">this newsgroup post</a>. My implementation is PHP, but it shouldn&#8217;t be hard to convert it to another platform (see the original thread for a Javascript implementation). Apologies for the rubbish formatting, WordPress isn&#8217;t great at handling code:</p>
<pre>function LongitudeToX( $lat, $lon, $map_zoom, $scale_value, $x_offset = 0 )
{
  $offset=16777216;
  $radius=$offset / pi();
  return ( ( ($offset+$radius*$lon*pi()/180)&gt;&gt;$map_zoom ) * $scale_value ) + $x_offset;
}
function LatitudeToY( $lat, $lon, $map_zoom, $scale_value, $y_offset = 0 )
{
  $offset=16777216;
  $radius=$offset / pi();
  return ( ( ($offset-$radius*log((1+sin($lat*pi()/180))/(1-sin($lat*pi()/180)))/2)&gt;&gt;$map_zoom ) * $scale_value ) + $y_offset;
}</pre>
<p>A few notes about using these functions:</p>
<ul>
<li>From what I can tell, the above code is based on Google Maps and the $map_zoom relates in some way to the &#8216;zoom level&#8217; of the map. I set it at 15 and it seemed to work OK.</li>
<li>Because the dimensions of your own map might not exactly match the assumed dimensions of the map used in the calculation, the $scale_value parameter allows you to adjust the output to fit more precisely. I had to specify two decimal places of scaling to get an exact fit.</li>
<li>Finally, the calculation assumes that the &#8216;origin point&#8217; of the map (x=0, y=0) will be at the top, left-hand corner. This isn&#8217;t the case on the map I&#8217;m working on (the origin is at the centre) so I included $x_offset and $y_offset parameters so that I could adjust the output values accordingly.</li>
</ul>
<p>In order to find the best values for the above parameters, I manually placed three widely-spaced temporary markers on the Flash map marking points whose latitude and longitude I already knew. Then I had the code render these points and adjusted the various parameters until the position of the generated points exactly matched the manually-placed markers.</p>
<p>I hope this code helps someone avoid wasting the sort of time I did yesterday!</p>
]]></content:encoded>
			<wfw:commentRss>http://the-stickman.com/uncategorized/converting-latitude-and-longitude-coordinates-to-map-x-and-y-values/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.222 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2017-06-14 19:20:26 -->

<!-- Compression = gzip -->