Develop location-aware, Metro style apps when your development system doesn't have GPS

The Windows Sensor and Location platform, first introduced by Microsoft back in Windows 7, allows applications to obtain information about, and react to, the hardware's physical environment. One of the many sensor types that are supported are those that provide location information, including GPS receivers.

While integrated GPS receivers are common in small form factor devices, in particular mobile phones, they are a relatively new addition to the traditional computing platform and though there are a wide number of external, consumer GPS devices that can be attached to the computer via USB ports, support for these devices as a Windows Location Sensor is very limited at the current time.

This presents a problem for the Windows Metro application developer: how do you develop a location-aware app when your development platform does not have a built-in location sensor?

The Windows Location Provider

Windows 8 includes a location "sensor" known as the Windows Location Provider that is enabled as a device by default. This is not a true hardware sensor, but rather a software solution that estimates your location through Wi-Fi triangulation and IP address resolution, using a database of wireless access point and IP addresses location information that is hosted on Microsoft-managed servers. For this service to work, your device must be connected to the internet.

The Windows Location Provider favors Wi-Fi triangulation over IP address resolution because it provides better positional accuracy, which Microsoft states can be within about 350 meters in dense, urban areas. Wi-Fi triangulation requires that:

  • You have a Wi-Fi device in your computer that is powered on. This can be an issue if your development work is taking place in a virtual machine, since most virtualization software also virtualizes the network interface. For Wi-Fi triangulation to work in such a configuration, it might be necessary to add a Wi-Fi interface card via a removable interface, such as USB or ExpressCard, that can be made directly visible to the guest OS.
  • You are located in an area with sufficient wireless access points in range in order to perform the triangulation. Rural areas, or other areas without dense Wi-Fi coverage, will limit the availability and accuracy of this option.

If Wi-Fi data is not available then the Windows Location Provider falls back to IP address resolution, a method that provides an accuracy no better than 25 km and which can be easily fooled by private network addresses such as you might find in your workplace network. As an example, right now the Windows Location Provider declares that I am located in Santa Clara, CA, the location of Intel's headquarters in the U.S., even though I am sitting in my office at our Hillsboro, OR location.

External GPS

If you require more precision than Wi-Fi triangulation can provide you will need to attach an external GPS. Unfortunately, support for GPS devices as a Windows Location Sensor is very limited at the current time, but there are third-party software solutions that create a sensor interface for any NMEA-compatible GPS receiver that is connected to a serial port. A Web search for "gps nmea sensor api" will turn up suitable options.

NMEA stands for the National Marine Electronics Association, and NMEA 0183 is a standard protocol used by GPS units to send and receive GPS data. Almost all GPS units can be configured to emit NMEA sentences, and the aforementioned software will work with NMEA data on any COM interface whether that is done directly via a native serial port, via a USB-to-serial adapter, Bluetooth, or any other method that presents a COM port to the local machine. The method for enabling NMEA output from your GPS varies from device to device, so consult your GPS manual for the correct procedure.

If you don't have a dedicated GPS device, all is not lost: you just have to turn to more creative options that don't sacrifice mobility.

Mobile Broadband Cards

Wireless 3G and 4G cards often times contain a GPS receiver in them, and depending on your card's manufacturer and your wireless carrier's software NMEA output may be an option that you can enable. Check your Wireless carrier's documentation to see if your card produces NMEA output on a virtual COM port.

Smartphones

Almost all modern smartphones contain a GPS receiver, and if the smartphone is Bluetooth-capable you can use third-party software to enable NMEA output over a Bluetooth connection. This method is more complicated and can require a great deal of patience since you must pair your phone with your laptop, create a COM port, and then enable the phone app to send NMEA data, but it works well enough. Similarly, there are some phone applications that can enable a TCP/IP server on the phone to emit NMEA data. Simply choose the one that works best for with your hardware.

With these options, you can develop your location-based Metro application using existing or inexpensive hardware, and start doing so today!

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.