Welcome to EMC Consulting Blogs Sign in | Join | Help

Keni Barwick - The Mobile Guy

rants and raves of all things Microsoft Windows Mobile - Moved to http://www.theMobileGuy.net

LocateMe - Using GPS in Compact Framework - Part One

 Now then people, I’m about to do something I haven’t done in a while… Blog some code!

Ok, you can get up of the floor now J

Then last time I did that was for the Kingston University Students, good luck by the way guys with your finals, and when I talked about the ‘not so hidden events’ in VisStu2k3.

“Why now?” I hear you ask, well I have just bought my self a Bluetooth TomTom on EBay and like any self respecting gadget man that I am I downloaded and installed as many GPS application’s that I could find for the SmartPhone and Pocket PC…

The natural ones are the mapping software, the aviation one, PocketFMS, is pretty cool, if only to sit on a flight and see where your going (no moving map stuff on BMI’s don’t you know!).

I had a look at this application SMARTLocator.GPS, I got it to work and it does a lot of things, very useful. But it just was way too much for what I’d like… I kind of would like an amalgamation of the GPS location uploading and the signature type idea that Celltrack give us.

So out came my trusty Tablet PC, I fired up Visual Studio 2003 and started on the solution…

LocateMe overview

Here is a little Viso Drawing that shows you what I’m thinking it should look like… But no one cares about little blue men and 3D drawings do they J

So, here is part one of LocateMe. The Web Service (source code)

I first created a couple of useful strings to use later;

            private string _PreviousLines = null;

            private string _Filename = null;


The following is the WebMethod that stores all the information;

            [WebMethod]

            public bool StoreLocation(    string userName,

string lat,

string latDirection,

string lon,

string lonDirection)

            {

 

Now populate those useful strings, we come to the CurrentFile() method later;

 

                  _Filename =  Server.MapPath("Locate"+userName+".html");

                  _PreviousLines = CurrentFile();

 

userName Was chosen to be added to the file so that you can do multiple users (nice idea that hey!)

 

Now lets create the file, well not all of it, that’s down how you want it to look;

                  try

                  {

                        // Create a file to write to.

                        using (StreamWriter sr = File.CreateText(_Filename))

                        {

                              sr.Write("

");

 

To ensure the header is easily removed and put back again, I placed all the code for it on one line.

 

 

                              sr.WriteLine("   

\r");

                              sr.Write(_PreviousLines);

                              sr.Close();

                              return true;

Next output the lines that were gathered from the last text file and return true.

 

Here we create a StreamReader that will read the current contents of the log file and store it into a string to use later…

 

            private string CurrentFile()

            {

                  if(File.Exists(_Filename))

                  {

                        using (StreamReader sr = new StreamReader(_Filename))

                        {

                              string cf = "";

                              string sLine = "";

                              int   iLine = 0;

                              // Open the file to read from.

                              // Return all but first line...

                              while ((sLine = sr.ReadLine()) != null)

                              {

                                    if(iLine>0)

                                    {

                                          cf += sLine;

                                    }

                                    iLine++;

                              }

                              return cf;

                        }

                  }

                  else

                        return "";

            }

The above isn’t rocket science, but hey I never said I was going to teach you how to get the shuttle up on time, crikkey even NASA can’t do that!

Next steps?

1)      Database it

2)      User Template report

3)      Use web.config (I must start doing that more often)

Tomorrow mobile client side J

 

Published 09 May 2005 11:21 by Keni.Barwick

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Jamie Thomson - Life, the universe and SSIS! said:

If you're reading this via a web browser rather than a blogreader then you'll notice this new image...
July 26, 2005 22:25
 

Jamie Thomson - Life, the universe and SSIS! said:

If you're reading this via a web browser rather than a blogreader then you'll notice this new image...
July 26, 2005 22:25
 

Jamie Thomson - Life, the universe and SSIS! said:

If you're reading this via a web browser rather than a blogreader then you'll notice this new image...
July 26, 2005 22:27
 

Jamie Thomson - Life, the universe and SSIS! said:

If you're reading this via a web browser rather than a blogreader then you'll notice this new image...
July 27, 2005 09:20
 

Jamie Thomson - Life, the universe and SSIS! said:

If you're reading this via a web browser rather than a blogreader then you'll notice this new image...
July 27, 2005 10:28

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

I'm an AllExpert at Allexperts.com

http://www.csthota.com/blogmap/ Subscribe in NewsGator Online
Locations of visitors to this page

Powered by Community Server (Personal Edition), by Telligent Systems