Click here to Skip to main content
15,897,334 members
Articles / Mobile Apps / Windows Mobile

Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant

Rate me:
Please Sign up or sign in to vote.
4.94/5 (126 votes)
10 Feb 2009CPOL10 min read 776K   11.1K   381  
A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections.Specialized;
using System.IO;

namespace DeepCast
{
    /// <summary>
    /// Class for managing user settings
    /// </summary>
    public class Settings
    {
        private static NameValueCollection _settings;
        private static string _settingsPath;

        static Settings()
        {
            _settingsPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            _settingsPath += @"\Settings.xml";

            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(_settingsPath);
            XmlElement root = xdoc.DocumentElement;
            System.Xml.XmlNodeList nodeList = root.ChildNodes.Item(0).ChildNodes;

            _settings = new NameValueCollection();
            _settings.Add("FireEagleToken", nodeList.Item(0).Attributes["value"].Value);
            _settings.Add("FireEagleSecret", nodeList.Item(1).Attributes["value"].Value);
            _settings.Add("TwitterEmail", nodeList.Item(2).Attributes["value"].Value);
            _settings.Add("TwitterPassword", nodeList.Item(3).Attributes["value"].Value);
            _settings.Add("FireEagleEnabled", nodeList.Item(4).Attributes["value"].Value);
            _settings.Add("TwitterEnabled", nodeList.Item(5).Attributes["value"].Value);
            _settings.Add("YahooMapsApiKey", nodeList.Item(6).Attributes["value"].Value);
            _settings.Add("OpenCellIDApiKey", nodeList.Item(7).Attributes["value"].Value);
        }

        public static void Update()
        {
            XmlTextWriter writer = new XmlTextWriter(_settingsPath, System.Text.UTF8Encoding.UTF8);
            writer.WriteStartDocument();
            writer.WriteStartElement("configuration");
            writer.WriteStartElement("appSettings");

            for (int i = 0; i < _settings.Count; ++i)
            {
                writer.WriteStartElement("add");
                writer.WriteStartAttribute("key", string.Empty);
                writer.WriteRaw(_settings.GetKey(i));
                writer.WriteEndAttribute();

                writer.WriteStartAttribute("value", string.Empty);
                writer.WriteRaw(_settings.Get(i));
                writer.WriteEndAttribute();
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.Close();
        }

        public static string FireEagleToken
        {
            get { return _settings.Get("FireEagleToken"); }
            set { _settings.Set("FireEagleToken", value); }
        }

        public static string FireEagleSecret
        {
            get { return _settings.Get("FireEagleSecret"); }
            set { _settings.Set("FireEagleSecret", value); }
        }

        public static string TwitterEmail
        {
            get { return _settings.Get("TwitterEmail"); }
            set { _settings.Set("TwitterEmail", value); }
        }

        public static bool FireEagleEnabled
        {
            get { return bool.Parse(_settings.Get("FireEagleEnabled")); }
            set { _settings.Set("FireEagleEnabled", value.ToString()); }
        }

        public static bool TwitterEnabled
        {
            get { return bool.Parse(_settings.Get("TwitterEnabled")); }
            set { _settings.Set("TwitterEnabled", value.ToString()); }
        }

        public static string TwitterPassword
        {
            get { return _settings.Get("TwitterPassword"); }
            set { _settings.Set("TwitterPassword", value); }
        }

        public static string YahooMapsApiKey
        {
            get { return _settings.Get("YahooMapsApiKey"); }
            set { _settings.Set("YahooMapsApiKey", value); }
        }

        public static string OpenCellIDApiKey
        {
            get { return _settings.Get("OpenCellIDApiKey"); }
            set { _settings.Set("OpenCellIDApiKey", value); }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer PageLabs
United States United States
I'm the founder of PageLabs, a web-based performance and SEO optimization site.

Give your site a boost in performance, even take a free speed test!

http://www.pagelabs.com

Comments and Discussions