<?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>Branded3 &#187; smartphones</title>
	<atom:link href="http://www.branded3.com/blogs/tag/smartphones/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.branded3.com</link>
	<description>Digital and SEO Agency</description>
	<lastBuildDate>Wed, 19 Jun 2013 10:59:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>SQL Function to find the direction between a mobile device and a POI</title>
		<link>http://www.branded3.com/blogs/sql-function-to-find-the-direction-between-a-mobile-device-and-a-poi/</link>
		<comments>http://www.branded3.com/blogs/sql-function-to-find-the-direction-between-a-mobile-device-and-a-poi/#comments</comments>
		<pubDate>Tue, 24 May 2011 09:21:02 +0000</pubDate>
		<dc:creator>Sanjay Zalke</dc:creator>
				<category><![CDATA[Blogs]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[How to...]]></category>
		<category><![CDATA[smartphones]]></category>

		<guid isPermaLink="false">http://www.branded3.com/?p=3080</guid>
		<description><![CDATA[Following on from my previous post about finding the true distance between a mobile user and a POI; I&#8217;m now going to look at how to find directions from a triangulated point by a series of mobile towers and a POI. Nowadays, mobiles are self aware geo-location devices, but not all smartphone&#8217;s are geo-location friendly]]></description>
			<content:encoded><![CDATA[<p>Following on from my previous post about <a href="http://www.branded3.com/b3labs/sql-function-find-distance-between-mobile-device-and-poi/">finding the true distance between a mobile user and a POI</a>; I&#8217;m now going to look at how to find directions from a triangulated point by a series of mobile towers and a POI.</p>
<p>Nowadays, mobiles are self aware geo-location devices, but not all smartphone&#8217;s are geo-location friendly and if you assume or target your application to a specific model; then you are losing out on a significant number of end users. So how can you make sure that your mobile application stays user-friendly?</p>
<p><span id="more-3080"></span>The application in question (pre-smartphone, I might add) had to show driving or walking directions for the end user on screen for all points of interest. But before the user chooses the category, we needed to provide a summary of nearest interest locations, and their distances and directions from the user location; so the user could then make a choice based on the distance and number of POI in that direction.</p>
<p>We calculated the distance using <a href="http://www.branded3.com/b3labs/sql-function-find-distance-between-mobile-device-and-poi/">haversine formula</a>, but where are these locations? Are they the same side or opposite to each other? There are high chances of the user choosing a location with a high density of POI near him rather a single POI.</p>
<p>Keeping in mind the end user&#8217;s dilemma, we decided to find the direction of each location with respect to the end user and show them on the mobile screen. But one major issue was still not addressed &#8211; was the end user facing North or South? To resolve this issue, our direction API came to the rescue, and we added a starting reference point with reference to a landmark. This resolved the issue with phones not supporting or embedding a compass-like device.</p>
<h3>The <span>approach:</span></h3>
<p><a href="http://www.branded3.com/wp-content/uploads/2011/05/mobile_position.jpg"><img class="alignright size-medium wp-image-3425" title="Mobile Position" src="http://www.branded3.com/wp-content/uploads/2011/05/mobile_position-300x300.jpg" alt="Mobile Position" width="300" height="300" /></a>To find the solution I turned to basic trigonometry; consider the mobile user as centre <em>(0,0)</em> of quadrant system, and POI scattered around in all quadrant with latitude and longitude as Cartesian points<em>(x1, y1)</em>. I had the distance between two points, and I needed the included angle between the x-axis and line generated by joining these two points.</p>
<p>The X-axis of quadrant represent East and West, and the Y-axis represent North and South. If you split the quadrant further it gives you, NE, NW, SE and SW directions. But our POI will not be exactly on these axis lines, so you need to consider an area formed by further splitting between these directions. In the image, an underground tube station on the X-axis and the other tube station next to it both appear to be East, even though the second tube station is not exactly East. This consideration helps me to group all POI in specific directions.</p>
<p>The clear advantage is gained from the end users point of view, the user will have more choice by following the East direction in this case rather than South-West &#8211; where few POI are located.</p>
<h3>The <span>solution:</span></h3>
<p>As you can see from the image, we can easily calculate directions if the included angle values lies in a specific direction pie. The following chart shows various directions and angular values:<br />
<a href="http://en.wikipedia.org/wiki/Trigonometric_function"><img class="alignright" title="Trigonometric function" src="http://upload.wikimedia.org/wikipedia/commons/7/7e/Trigonometry_triangle.svg" alt="" width="200" height="208" /></a></p>
<table style="margin-left: 20px; margin-bottom: 20px; font-size: 12px; border-colapse: colapse;" width="50%">
<tbody>
<tr>
<th style="padding: 4px 0; border-bottom: 1px solid #000; font-weight: bold;">Angle in degrees</th>
<th style="padding: 4px 0; border-bottom: 1px solid #000; font-weight: bold;">Direction</th>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">0 &#8211; 22.50</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">East</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">22.51 &#8211; 67.49</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">North East</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">67.50 &#8211; 112.50</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">North</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">112.51 &#8211; 157.49</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">North West</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">157.50 &#8211; 202.50</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">West</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">205.51 &#8211; 247.49</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">South West</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">247.50 &#8211; 292.50</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">South</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">292.51 &#8211; 337.49</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">South East</td>
</tr>
<tr>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">337.50 &#8211; 360.00</td>
<td style="padding: 4px 0; border-bottom: 1px solid #ccc;">East</td>
</tr>
</tbody>
</table>
<p>To calculate the included angle of vertex A, I assume vertex A is on the centre of quadrant<em> (0,0)</em> and vertex B is POI. So in theory, the tangent of angle C should return distance &#8220;b&#8221; (AC). As soon as the distance &#8220;b&#8221; is calculated, angle A can be calculated using either sine or cosine formula.<br />
<a href="http://www.branded3.com/wp-content/uploads/2011/05/equation.png"><img class="alignleft size-medium wp-image-3451" title="arctan equation" src="http://www.branded3.com/wp-content/uploads/2011/05/equation-300x64.png" alt="" width="300" height="64" /></a><br />
The whole equation is resolved to a single arctan formula. This function returns the value in radians, so we need to convert it to degrees before applying any calculation logic. But soon the limitations of this approach are highlighted, it can only return values between -90 and +90 degrees and needs major adjustments to get the final value.</p>
<p>As my first attempt failed, I turned towards <a href="http://mathforum.org/library/drmath/view/55417.html">mathforum</a>, I found a related solution, with some shortcomings. After some adjustments and a couple of days of testing with actual data, ultimately I nailed this task of finding directions.</p>
<h3>SQL <span>Function:</span></h3>
<p>The formula from mathforum was written considering North being X-axis, so I have to turn the axis anti-clockwise by 90 degrees.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>Direction<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#40;</span>
	@Lat1			<span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	@Lat2			<span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	@Lon1			<span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	@Lon2			<span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">EXECUTE</span> <span style="color: #993333; font-weight: bold;">AS</span> CALLER
<span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #993333; font-weight: bold;">BEGIN</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">DECLARE</span> @dLat <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @dLon <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
                    @angle <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @RetVal NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @Pre_angle <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">DECLARE</span> @Constant <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Not found...'</span>
	<span style="color: #993333; font-weight: bold;">SET</span> @Pre_angle <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
	<span style="color: #993333; font-weight: bold;">SET</span> @CONSTANT <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">999999999.00</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">SET</span> @dLat <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>@Lat2 <span style="color: #66cc66;">-</span> @Lat1<span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">SET</span> @dLon <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>@Lon2 <span style="color: #66cc66;">-</span> @Lon1<span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* -- Approach 2 */</span>
	<span style="color: #993333; font-weight: bold;">DECLARE</span> @y <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @x <span style="color: #993333; font-weight: bold;">NUMERIC</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">SET</span> @y <span style="color: #66cc66;">=</span> SIN<span style="color: #66cc66;">&#40;</span>@Lon2 <span style="color: #66cc66;">-</span> @Lon1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> COS<span style="color: #66cc66;">&#40;</span>@Lat2<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1.0</span>
	<span style="color: #993333; font-weight: bold;">SET</span> @x <span style="color: #66cc66;">=</span> COS<span style="color: #66cc66;">&#40;</span>@Lat1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> SIN<span style="color: #66cc66;">&#40;</span>@Lat2<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> SIN<span style="color: #66cc66;">&#40;</span>@Lat1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> COS<span style="color: #66cc66;">&#40;</span>@Lat2<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> COS<span style="color: #66cc66;">&#40;</span>@Lon2 <span style="color: #66cc66;">-</span> @Lon1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1.0</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@y &amp;gt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">BEGIN</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x &amp;gt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> DEGREES<span style="color: #66cc66;">&#40;</span>ATN2<span style="color: #66cc66;">&#40;</span>@y<span style="color: #66cc66;">,</span> @x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1.0</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x &amp;lt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">180.00</span> <span style="color: #66cc66;">-</span> DEGREES<span style="color: #66cc66;">&#40;</span>ATN2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span>@y<span style="color: #66cc66;">,</span> @x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1.0</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">90.00</span>
	<span style="color: #993333; font-weight: bold;">END</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@y &amp;lt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">BEGIN</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x &amp;gt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> DEGREES<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> ATN2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span>@y<span style="color: #66cc66;">,</span> @x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1.0</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x &amp;lt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>DEGREES<span style="color: #66cc66;">&#40;</span>ATN2<span style="color: #66cc66;">&#40;</span>@y<span style="color: #66cc66;">,</span> @x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">180.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1.0</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">270.00</span>
	<span style="color: #993333; font-weight: bold;">END</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@y <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">BEGIN</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x &amp;gt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.00</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x &amp;lt; <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">180.00</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@x <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0.00</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> @CONSTANT
	<span style="color: #993333; font-weight: bold;">END</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Just for Display in Debug</span>
	<span style="color: #993333; font-weight: bold;">SET</span> @Pre_angle <span style="color: #66cc66;">=</span> @angle
&nbsp;
	<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle !<span style="color: #66cc66;">=</span> @CONSTANT<span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">BEGIN</span>
		<span style="color: #808080; font-style: italic;">-- This formaula refer x-axis as North direction,</span>
		<span style="color: #808080; font-style: italic;">-- but while assigning Direction Character, is considering</span>
                <span style="color: #808080; font-style: italic;">-- x-axis as West (as of Co-Ordinate System)</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> @angle <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">90</span> 
&nbsp;
		<span style="color: #808080; font-style: italic;">-- Minor Adjustment for for value range</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle &amp;lt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">BEGIN</span>
			<span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> ABS<span style="color: #66cc66;">&#40;</span>@angle<span style="color: #66cc66;">&#41;</span>
			<span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> @angle <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">90</span> <span style="color: #808080; font-style: italic;">-- Previously Values were -ve so only 90 = total 180</span>
		<span style="color: #993333; font-weight: bold;">END</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">-- No Modulo function is available for Float, so a loop is implemented</span>
		<span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle &amp;gt; <span style="color: #cc66cc;">360</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">BEGIN</span>
			WHILE<span style="color: #66cc66;">&#40;</span>@angle &amp;gt; <span style="color: #cc66cc;">360</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #993333; font-weight: bold;">BEGIN</span>
				<span style="color: #993333; font-weight: bold;">SET</span> @angle <span style="color: #66cc66;">=</span> @angle <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">180</span>
			<span style="color: #993333; font-weight: bold;">END</span>
		<span style="color: #993333; font-weight: bold;">END</span>
	<span style="color: #993333; font-weight: bold;">END</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Find Direction Values; Practical data suggest to change this Direction</span>
        <span style="color: #808080; font-style: italic;">-- with a 90 degree anticlockwise shift.</span>
	<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@angle <span style="color: #66cc66;">=</span> @CONSTANT<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">-- Origin [Same Position]</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">22.5</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'E'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">22.51</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">67.49</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'NE'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">67.5</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">112.5</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'N'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">112.51</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">157.49</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'NW'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">157.5</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">202.5</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'W'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">205.51</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">247.49</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SW'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">247.5</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">292.5</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'S'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">292.51</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">337.49</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SE'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>@angle <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">337.5</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">360.00</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'E'</span>
	<span style="color: #993333; font-weight: bold;">ELSE</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @RetVal <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Return Direction Data</span>
	<span style="color: #993333; font-weight: bold;">RETURN</span> @RetVal
<span style="color: #993333; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>This formula accepts latitude and longitude values and returns a two-character string denoting direction. If the user and POI is on centre or the same location, it just returns a blank string.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.branded3.com/blogs/sql-function-to-find-the-direction-between-a-mobile-device-and-a-poi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>M-commerce proves a hit with shoppers</title>
		<link>http://www.branded3.com/blogs/m-commerce-proves-a-hit-with-shoppers/</link>
		<comments>http://www.branded3.com/blogs/m-commerce-proves-a-hit-with-shoppers/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 13:38:56 +0000</pubDate>
		<dc:creator>Felicity Crouch</dc:creator>
				<category><![CDATA[Blogs]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Think tank]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[m-commerce]]></category>
		<category><![CDATA[mobile web]]></category>
		<category><![CDATA[online shopper]]></category>
		<category><![CDATA[smartphones]]></category>

		<guid isPermaLink="false">http://branded3.agencypreview.info/?p=1700</guid>
		<description><![CDATA[Yet another innovation that was doomed for failure by the country’s foreboding cynics, has proved to be a growing trend. The emergence of an m-commerce market; allowing online consumers to shop on their mobiles; didn’t exactly impress from the take-off. But a study released by ForeSee Results has revealed that increasing numbers of people are]]></description>
			<content:encoded><![CDATA[<p>Yet another innovation that was doomed for failure by the country’s foreboding cynics, has proved to be a growing trend.</p>
<p>The emergence of an m-commerce market; allowing online consumers to shop on their mobiles; didn’t exactly impress from the take-off. But a study released by ForeSee Results has revealed that increasing numbers of people are making their transactions via mobile web, and that number is set to swiftly accelerate.</p>
<p><span id="more-1700"></span><br />
The study examined the habits of 10,000 Christmas shoppers over the seasonal period, focusing on their use of the top 40 online retail sites, including technical leaders Apple, e-commerce giant Amazon, and lucrative toy champion Toys ‘R’ Us.</p>
<p>The results found that more than half of online shoppers are already using, or plan to use, their phones in future for shopping. A total of 11% of the studied shoppers actually purchased via their mobile web, compared to only 2% in the same period in 2009.</p>
<p>A staggering 56% used their mobile web to compare prices, whilst 46% compared products. Although not necessarily buying straight from their mobiles, it is this speedy development in using m-commerce tasks that forecast the success of m-commerce transactions.</p>
<p>Kevin Ertell, Vice President of Retail Strategy at ForeSee Results commented on the possibilities the study has opened: “This finding indicates a huge opportunity for retailers with sophisticated, user-centric mobile sites and apps.”</p>
<p>Whilst commenting on the vast array of opportunities m-commerce has opened; Ertell also relays a valid point. Success will only come to the mobile sites and apps which are user-friendly and impart an enjoyable experience. The study also revealed that customers were less than satisfied with the shopping experience, so perhaps much consideration has to be paid to the usability and overall encounter with the site or app.</p>
<p>When suddenly realising my contact lens stash was running seriously low, and being away from my laptop, I took to my iPhone to order my next supply. What would have taken less than four minutes on the laptop, ordering and paying for my lenses ended up taking 15 minutes on my phone.</p>
<p>In a world where web users want immediacy and efficiency; attempting to scroll back and forth whilst searching for products, and zooming in and out to enter card details; is just all too time-consuming. Mobile sites and apps shouldn’t just be a scaled down version of their online counterparts, they need to add value to the brand, and be specifically optimised for mobile.</p>
<p>So much time and money is thrown into reinforcing brand values and making the shopping experience enriched for the consumer; retailers need to put the same effort into mobile shopping.</p>
<p>By 2012, the cost of smartphones will have reduced significantly and they’ll be more widespread; meaning the possibility of m-commerce taking over will become a reality. Experts predict that the UK mobile commerce market will have doubled by 2013, making now an ample time to begin transforming the mobile shopping world.</p>
<p>House of Fraser has already launched their mobile transactional website, and has seen mobile sales grow by 660%, reinforcing the overwhelming potential of m-commerce.</p>
<p>Although the capabilities of mobile shopping are vast; the possibility for it to fail considerably for retailers is also present. If mobile security is not integrated within the mobile site or app, consumers will lose their trust in a brand and not use the retailer across any platform.</p>
<p>When commenting on how I check my bank balance on my mobile, I still get gasps from friends and family who can’t believe I exchange such important information via mobile web. Mobile security still remains the one issue affecting the interest in m-commerce, with many people believing it isn’t safe.</p>
<p>The younger generation are most comfortable utilising m-commerce, as with most technology trends. But as always, the more popular and widespread something becomes, the more people trust it and incorporate it into their everyday lives.</p>
<p>Thanks to faster speeds, a wider range of internet-enabled phones, and the ability to manage time better; m-commerce is sure to engulf the online retail market as we know it.</p>
<p>The time is nigh for retailers to jump on the technical bandwagon and take advantage of this amplifying development. It isn’t a case of will the m-commerce market dominate; it’s a case of when.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.branded3.com/blogs/m-commerce-proves-a-hit-with-shoppers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: www.branded3.com @ 2013-06-19 20:07:44 by W3 Total Cache -->