使用 .NET CF 从 WM6 手机查询 GPS 位置(仅限经度和纬度)

发布于 2024-09-11 23:06:09 字数 181 浏览 4 评论 0原文

我正在寻找一个非常简单的解决方案,如何从 WM6 手机检索 GPS 数据。我不是在寻找 GPS 包装库(Google 似乎只找到 GPS 库...)。我希望有一段代码可以做到这一点:启动 GPS,检索经度和纬度,结束 GPS。而已。我想对于 .NET Compact Framework,我需要使用 P/Invoke。
有什么想法吗?多谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

述情 2024-09-18 23:06:10

你说你不是在寻找 GPS Wrapper 库,但你想查询 GPS。最简单的方法是使用 GPS 中间库,它是一个流接口驱动程序。从托管代码调用它需要某种形式的包装器来进行 P/Invoke 调用。无论您是编写它还是使用已经存在的包装器都取决于您,但无论如何您都将使用包装器。

要简单地打开 GPS、获取位置并关闭它,需要执行一组三个调用: GpsOpenDeviceGpsGetPositionGpsCloseDevice,但是在调用 GpsOpenDevice 之后,您确实需要知道驱动程序何时初始化在调用 GpsGetPosition 之前,因此您可能还需要调用 GpsGetDeviceState 来知道什么时候准备好。

由于您不需要通知,因此对 GpsOpenDevice 的调用很简单 - 只需为所有参数传入零(或 IntPtr.Zero,具体取决于您定义 P/Invoke 方法的方式)。

GpsGetPosition 获取一个指向 GPS_POSITION 结构的指针。它是一个有点丑陋的野兽,但还不错,因为它没有任何要分配的指针,并且 CF Marshaler 在一点帮助下可以相当轻松地对其进行编组。

我不打算在这里编写该代码,因为它很长,而且它已经在 Microsoft 随 WinMo SDK 提供的 GPS 示例应用程序中完成(在您的硬盘上查看 %PROGRAM FILES%\Windows Mobile 6 SDK\示例\PocketPC\CS\GPS)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文