views:

11

answers:

1

Hello there,
I am looking for a very simple solution of how to retrieve GPS data from WM6 cell phone. I am not looking for a GPS wrapper library (Google seems to find ONLY GPS libs...). I'd appreciate just a piece of code which does exactly this: start gps, retrieve long and lat, end gps. Nothing more. I guess with .NET Compact Framework I'll need to use P/Invoke.
Any ideas? THanks a lot.

A: 

You say you're not looking for a GPS Wrapper library, but you want to query the GPS. The easiest way to do that is by using the GPS intermediate library, which is a stream interface driver. Calling it from managed code requires some form of wrapper that makes the P/Invoke calls. Whether you write that or you use one that already exists is up to you, but you're going to be using a wrapper regardless.

To simply open the GPS, get a position and close it is going to be a set of three calls: GpsOpenDevice, GpsGetPosition and GpsCloseDevice, however after calling GpsOpenDevice you really need to know when the driver is initialized before you call GpsGetPosition, so you probably need to also call GpsGetDeviceState to know when it's ready.

Since you don't need notifications, the call to GpsOpenDevice is simple - just pass in zeros (or IntPtr.Zero depending on how you define your P/Invoke method) for all of the parameters.

GpsGetPosition takes a pointer to a GPS_POSITION struct. It's a little bit of an ugly beast, but not too bad as it doesn't have any pointers to be allocated and the CF Marshaler, with a little help, can marshal it fairly easily.

I've not going to write that code here as it's lengthy, plus it's already done in the GPS sample app that Microsoft provides with the WinMo SDKs (look on your hard drive at %PROGRAM FILES%\Windows Mobile 6 SDK\Samples\PocketPC\CS\GPS).

ctacke