Geolocation in Windows 7 without GPS

    Have you seen many laptops that are equipped with a GPS sensor? Approximate estimates can be found here , 58 pieces out of 4380, that is 1.3%. Frankly speaking - not a lot. It is difficult to name all the reasons why manufacturers do not equip laptop computers, in general, with an inexpensive chip, but our note is just about how to provide your laptop with geolocation functionality, even if you do not have a GPS sensor. And at the same time you will learn how very simple it is to get your coordinates programmatically.

    Talk about the weather?


    Do you use a weather gadget in Windows 7? Until recently, I didn’t use it, because I was too lazy to drive another city into the hand (and I travel a lot). The option to automatically detect my coordinates did not work.
    Windows 7 Weather Gadget Settings
    The thing is that this gadget is trying to determine your coordinates through the Windows7 Sensor API . And it requires a sensor driver. Recently, while preparing a presentation for Platform 2011, I came across a Geosense sensor , which very well determines the coordinates. For weather services, they are 100% suitable.
    Windows 7 Weather Gadget
    In fact, the accuracy is high, it works on the basis of the Google Location Service (WiFi and IP base) and I managed to test it in at least three places:
    • WTC on Krasnopresnenskaya via WiFi which was in the hotel. He determined the location accurate to the building.
    • Similarly, he remarkably determined the location when I was connected via cable (IP) to the WTC
    • In Uglich, I determined the location via WiFi accurate to home
    • Now I’m sitting in Sheremetyevo D and again I determined the location accurate to the terminal.

    Do not forget to configure this sensor as the default one, since the Orion sensor in Russia, unfortunately, does not work accurately enough.Location Sensor Settings

    We determine the coordinates programmatically


    Excuse me sir, where are we?
    -You are in the basket of the balloon, gentlemen.
    Holmes, in a whisper: -Watson, I bet this man is a programmer.



    The Windows 7 Sensor API is also implemented in the .NET Framework 4.0. You just need to write literally 3 lines of code to understand where you are:

    Location Code
    I am now in Sheremetyevo D, connected to the “Terminal-D WiFi-Free” hotspot and this is what this program returns to me:
    Geolocation Results in BingMaps

    A bit about security


    Of course, in Windows 7 there is an opportunity to set permissions to use this API. If your application tries to determine the coordinates, a warning will surely appear:
    Sensor On
    And you can also configure user access:
    Sensor Configuration for Users
    All calls to the geolocation API are recorded in the log:
    image

    Summary


    Of course, such geolocation does not replace GPS at all. First of all, because of accuracy, and sometimes mistakes sometimes take place. But it can help out in cases where GPS does not work (in buildings, in the presence of a bad signal) and if you have an Internet connection. And to determine the weather or other contextual services (for example, in social applications) is suitable for sure.

    The source code for a simple console application using the Geolocation API can be downloaded from the MSDN Code Gallery at code.msdn.microsoft.com/Windows-7-Geolocation-API-25585fac

    Also popular now: