Getting position of a Windows Mobile 5 device on the cheap

Let's say that you have an application where if it had the position of the device it would be cool, but if it didn't have the position it's not really a big deal.  Imagine a home screen plugin for instance where it would be an added bonus to display the next day's weather, but not critical.  In this case what you want to do is ask for the device's position if the device happens to know it already but not turn a GPS unit and drain the battery just for a pri3 scenario.

GPSID supports this functionality.  If you call GPSOpenDevice() that tells GPSID to start up the underlying GPS device, if there is one, which potentially causes the battery drain.  However if you just call GPSGetPosition and pass in a NULL HANDLE for the hGPSDevice and don't call GPSOpenDevice, it will only try to get a cached position.  If one's available cool, if not life goes on.  Obviously this won't help if you're doing a navigation app since you need to turn the GPS unit on no matter what.

This feature is already doc'd here, but as I've been asked how to do this a few times I'm guessing no one reads the docs :(.  At a minimum I hope that even if you're not using location enabled apps now because you don't want to deal with a battery drain, this blog has given you some ideas.

https://msdn.microsoft.com/library/default.asp?url=/library/en-us/mobilesdk5/html/wce51lrfGPSGetLocation.asp

[Author: John Spaith]