Showing posts with label mobile. Show all posts
Showing posts with label mobile. Show all posts

Wednesday, January 7, 2009

Getting mobile location on Windows Mobile 6

As part of my ongoing mapping project I wanted to be able to update my server with my location - the first step was to use the GPS built into my Windows Mobile 6.

I used the GPS Intermediate Driver to do this, and the code provided by the Windows Mobile 6 SDK.

The simplest code that can be written references the sample library provided by the SDK. My sub-80 line program to do this looks like this:

using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Samples.Location;

namespace MobileLocate
{
 public partial class FormMain : Form
 {
  Gps gps = new Gps();
  GpsDeviceState device = null;
  GpsPosition position = null;

  public FormMain()
  {
   InitializeComponent();

   // updates from GPS need to be delgate to the UI thread
   EventHandler uiUpdatesOnApplicationThread = new EventHandler(UpdateUI);

   // handle device state updates
   gps.DeviceStateChanged += new DeviceStateChangedEventHandler(delegate(object sender, DeviceStateChangedEventArgs args)
   {
    device = args.DeviceState;

    Invoke(uiUpdatesOnApplicationThread);
   });

   // handle location updates
   gps.LocationChanged += new LocationChangedEventHandler(delegate(object sender, LocationChangedEventArgs args)
   {
    position = args.Position;

    Invoke(uiUpdatesOnApplicationThread);
   });

   gps.Open();
  }

  void UpdateUI(object sender, System.EventArgs args)
  {
   if (device != null)
    textBoxDev.Text = device.FriendlyName + " " + device.ServiceState + ", " + device.DeviceState;

   if (position != null)
   {
    if (position.LatitudeValid && position.LongitudeValid)
     textBoxLocation.Text = String.Format("{0}, {1}", position.Latitude, position.Longitude);

    if (position.SatellitesInSolutionValid &&
      position.SatellitesInViewValid &&
      position.SatelliteCountValid)
    {
     textBoxSats.Text = "Satellite Count:\n   " + position.GetSatellitesInSolution().Length + "/" +
       position.GetSatellitesInView().Length + " (" +
       position.SatelliteCount + ")\n";
    }
   }
  }

  private void FormMain_Closed(object sender, EventArgs e)
  {
   // ensures application closes cleanly
   if (gps.Opened)
    gps.Close();
  }
 }
}

I ran this just now, and stuck the co-ordinates into a map - and it works a treat!

I plan to extend this code to allow it to report into a central server (with a username/password) and then be able to show this on the map. This will form one of the overlays (more later on this) that can be incorporated onto a map - this means you could chose to have the location of a set of users appear on a map (they will have to be permissions on this, and maybe a "how precise" feature to mask exact location)

From the mobile viewpoint, it should be easy enough to use the vector maps to show a local map on the mobile phone as well. For the moment I may just add the ability for the system to tell you where you are (for example postcode in the UK using http://www.freethepostcode.org/ data), or just the nearest city or pub! ;-)

Wednesday, October 8, 2008

Minimalistic phone instructions

So I've just got a "free" upgrade to my phone from Orange.

Its the HTC Touch Diamond p3700, a much smaller phone than my previous. It comes in very styled packaging and contains a "quick start" pamphlet from Orange and quick guide to use the touch interface from HTC.

That's all the documentation you get, nothing else. So how the heck do I use it, or more importantly set it up? ah, I found a three step process on the "quick start" cover:
  1. Insert SIM card
  2. Charge phone
  3. Register your Orange phone

That's it, nowhere does it say how the feck to do step 3 - maybe they felt that putting in "ring orange on the freephone registration number" was too helpful, or maybe they realised that if they did this that someone might ask the even more troubling question:

What's the number! argh, its not mentioned anywhere in the packaging! (why would it be since they never told you to ring it in the first place) Anyway I had to look it up on Orange's website, where the following steps are recommended for setting up a new phone:

  1. charge the battery
  2. transfer your personal numbers from your old SIM card to your new phone's memory
  3. call 0800 079 0027 to register your upgrade and new SIM card

Obviously these instructions are too detailed to put in the box..