<?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>Windows CE Programming &#187; GPS</title>
	<atom:link href="http://www.hjgode.de/wp/tag/gps/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hjgode.de/wp</link>
	<description>Windows Mobile Development and usage</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:53:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<!--CodeProjectFeeder channel--><category>CodeProject</category><generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using ws.geonames.org timezone webservice without WSDL</title>
		<link>http://www.hjgode.de/wp/2010/03/04/using-ws-geonames-org-timezone-webservice-without-wsdl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-ws-geonames-org-timezone-webservice-without-wsdl</link>
		<comments>http://www.hjgode.de/wp/2010/03/04/using-ws-geonames-org-timezone-webservice-without-wsdl/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 13:08:08 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[blocking]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[timezone]]></category>
		<category><![CDATA[timezone-web-service]]></category>
		<category><![CDATA[windows mobile]]></category>
		<category><![CDATA[ws.geonames.org]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=413</guid>
		<description><![CDATA[How to use ws.geonames.org/timezone and other raw webservices from windows mobile dotnet compact framework]]></description>
			<content:encoded><![CDATA[<p>The great site geonames.org offers some webservices. One of these is called timezone and will give you the timezone information for a given geographic Latitude and Longitude. With a GPS enabled Windows Mobile device you can so query the webservice and get timezone informations for the current location.</p>
<p>Unfortunately the webservice does not offer WSDL and so you have to write your own wrapper class. I wrote a small class that does the HttpWebRequest and decodes the xml reponse for easy use in your application.</p>
<p><span id="more-413"></span></p>
<p>When you query the webservice you have to use the following form:</p>
<pre><a href="http://ws.geonames.org/timezone?lat=47.01&amp;lng=10.2">http://ws.geonames.org/timezone?lat=47.01&amp;lng=10.2</a></pre>
<p>The answer will then be:</p>
<pre>         &lt;geonames&gt;
            &lt;timezone&gt;
                &lt;countryCode&gt;AT&lt;/countryCode&gt;
                &lt;countryName&gt;Austria&lt;/countryName&gt;
                &lt;lat&gt;47.01&lt;/lat&gt;
                &lt;lng&gt;10.2&lt;/lng&gt;
                &lt;timezoneId&gt;Europe/Vienna&lt;/timezoneId&gt;
                &lt;dstOffset&gt;2.0&lt;/dstOffset&gt;
                &lt;gmtOffset&gt;1.0&lt;/gmtOffset&gt;
                &lt;rawOffset&gt;1.0&lt;/rawOffset&gt;
                &lt;time&gt;2010-03-02 12:14&lt;/time&gt;
            &lt;/timezone&gt;
        &lt;/geonames&gt;</pre>
<p>The sample application will use this answer and shows the result:</p>
<p><a rel="attachment wp-att-414" href="http://www.hjgode.de/wp/2010/03/04/using-ws-geonames-org-timezone-webservice-without-wsdl/clipboard02/"><img class="alignnone size-full wp-image-414" title="Get Timezone by GPS" src="http://www.hjgode.de/wp/wp-content/uploads/2010/03/Clipboard02.gif" alt="" width="240" height="320" /></a></p>
<p>The attached Visual Studio 2005 SmartDevice Windows Mobile 5 project has two classes: GeonamesTZ is a blocking class and geonamesTZ is a non-blocking class.</p>
<p>A blocking code is never good and so I implemented the class with an event. To use the class include a using statement for the geonames namespace and then initialize a new geonamesTZ object. Then add an event handler for the object’s event delegate. Finally add a event handler function that will get the timezone data.</p>
<pre lang="CSHARP">using geonames;
    public partial class Form1 : Form
    {
        geonamesTZ myGeoTZ;
        geonamesTZfields tzFields;

        public Form1()
        {
            InitializeComponent();
            myGeoTZ = new geonamesTZ();
            myGeoTZ.geonamesEventHandler += new geonamesEvent(myGeoTZ_geonamesEvent);
        }

        void myGeoTZ_geonamesEvent(object sender, geonamesEventArgs e)
        {
            //Cursor.Current = Cursors.Default;
            //MessageBox.Show(e.m_myEventArgumentdata.strCountryName);
            tzFields = e.m_myEventArgumentdata;
            updateUI(tzFields);
        }
</pre>
<p>To get the timezone information you have to call the class function</p>
<pre lang="CSHARP">            myGeoTZ.startRequest(txtLat.Text, txtLng.Text); //the answer should come...</pre>
<p>and after some time the function myGeoTZ_geonamesEvent is called with the received data. Using the event driven approach will give the possibility to write an app that reads GPS data and updates timezone information in the background. Maybe this is usefull for Windows Mobile phones that often ’fly’ between continents. The timezone can then be updated in background.</p>
<p>As updating the UI from a different thread may fail, the updateUI function is implemented like this:</p>
<pre lang="CSHARP">        // see http://blog.opennetcf.com/ctacke/2008/12/03/ControlInvokeWithoutExplicitDelegates.aspx
        public void updateUI(geonames.geonamesTZfields myTZinfos)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(delegate(object o, EventArgs a)
                {
                    txtDSToffset.Text = myTZinfos.dstOffset.ToString();
                    txtGMToffset.Text = myTZinfos.gmtOffset.ToString();
                    txtTimzoneID.Text = myTZinfos.strTimezoneID;
                    txtTime.Text = myTZinfos.tzTime.ToString();
                    txtTZcountryCode.Text = myTZinfos.strCountryCode;
                    lblStatus.Text = myTZinfos.strLastError;
                }));
            }
            else
            {
                txtDSToffset.Text = myTZinfos.dstOffset.ToString();
                txtGMToffset.Text = myTZinfos.gmtOffset.ToString();
                txtTimzoneID.Text = myTZinfos.strTimezoneID;
                txtTime.Text = myTZinfos.tzTime.ToString();
                txtTZcountryCode.Text = myTZinfos.strCountryCode;
                lblStatus.Text = myTZinfos.strLastError;
            }
        }</pre>
<p>That was much easier than doing invokes on every txt field separately.</p>
<p>The raw xml response is parsed by another class called xml_helper. This class makes it easy to extract single values from the raw xml response. Here is one example:</p>
<pre lang="CSHARP">namespace xml_helper{
    public static class xml_helper
    {
        public static string getStrSetting(StringBuilder sb, String sField)
        {
            string sVal = sb.ToString();
            string sFieldString = "&lt;" + sField + "&gt;";
            int iIdx = sVal.IndexOf(sFieldString);
            string sResult = "";
            if (iIdx &gt;= 0)
            {
                string fieldStr = sVal.Substring(iIdx);
                string ssidStr = fieldStr.Remove(0, sFieldString.Length);
                iIdx = ssidStr.IndexOf("&lt;/");
                sResult = ssidStr.Substring(0, iIdx);
            }
            return sResult;
        }</pre>
<p>These simple functions can be easily used on a xml file with single element data. Just call, for example getStrSettings with the xml string and the setting you would like to get.</p>
<p>Download Visual Studio 2005 SmartDevice Windows Mobile 5 project: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=82" title="Downloaded 244 times">TimeZone by GPS demo application</a> -  (Hits: 244, size: 52.09 KB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F03%2F04%2Fusing-ws-geonames-org-timezone-webservice-without-wsdl%2F&amp;title=Using+ws.geonames.org+timezone+webservice+without+WSDL" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F03%2F04%2Fusing-ws-geonames-org-timezone-webservice-without-wsdl%2F&amp;title=Using+ws.geonames.org+timezone+webservice+without+WSDL" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F03%2F04%2Fusing-ws-geonames-org-timezone-webservice-without-wsdl%2F&amp;title=Using+ws.geonames.org+timezone+webservice+without+WSDL" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F03%2F04%2Fusing-ws-geonames-org-timezone-webservice-without-wsdl%2F&amp;T=Using+ws.geonames.org+timezone+webservice+without+WSDL" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F03%2F04%2Fusing-ws-geonames-org-timezone-webservice-without-wsdl%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F03%2F04%2Fusing-ws-geonames-org-timezone-webservice-without-wsdl%2F&amp;t=Using+ws.geonames.org+timezone+webservice+without+WSDL" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/03/04/using-ws-geonames-org-timezone-webservice-without-wsdl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enhanced GPS sample</title>
		<link>http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enhanced-gps-sampe</link>
		<comments>http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/#comments</comments>
		<pubDate>Tue, 12 May 2009 17:04:50 +0000</pubDate>
		<dc:creator>hjgode</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[GPS sample]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=41</guid>
		<description><![CDATA[First, the GPS sample provided by MS is a very good starting point for C# programmers getting GPS to work. GREAT! I used the sample and modded it to get more informations on the screen. Unfortunately, the sample is somehow not thread safe and I needed to change the code at least for Windows Mobile [...]]]></description>
			<content:encoded><![CDATA[<p>First, the <a href="http://msdn.microsoft.com/en-us/library/bb158699.aspx" target="_blank">GPS sample</a> provided by MS is a very good starting point for C# programmers getting GPS to work. GREAT!</p>
<p>I used the sample and modded it to get more informations on the screen.</p>
<p><span id="more-41"></span>Unfortunately, the sample is somehow not thread safe and I needed to change the code at least for Windows Mobile 6.</p>
<p>As I run GPS sample on a WM6.1 device it crashes with NullReferenceException. I digged around and rewrote the UI update routines to use MessageHandler, and now it works fine.</p>
<p>If you are only using the simple GPS sample, it maywork without modifications like the replacement of Invoke by BeginInvoke.</p>
<p><img title="gps2008.jpg" src="http://community.intermec.com/t5/image/serverpage/image-id/81i75B39840A699A9A2/image-size/original?v=mpbl-1&amp;px=-1" border="0" alt="gps2008.jpg" align="center" /></p>
<p>Free source code:</p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=4" title="Downloaded 286 times">Modded GPS sample</a> - A modded GPS sample in C# (Hits: 286, size: 713.46 KB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F12%2Fenhanced-gps-sampe%2F&amp;title=Enhanced+GPS+sample" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F12%2Fenhanced-gps-sampe%2F&amp;title=Enhanced+GPS+sample" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F12%2Fenhanced-gps-sampe%2F&amp;title=Enhanced+GPS+sample" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F12%2Fenhanced-gps-sampe%2F&amp;T=Enhanced+GPS+sample" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F12%2Fenhanced-gps-sampe%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F12%2Fenhanced-gps-sampe%2F&amp;t=Enhanced+GPS+sample" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

