开发者

Querying GPS location (only long. & lat.) from WM6 phone using .NET CF

开发者 https://www.devze.com 2023-01-09 18:13 出处:网络
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 piec

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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消