Have you seen a lot of 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 much. It’s hard to name all the reasons why manufacturers do not equip laptops with an inexpensive chip, but our note is about how to equip your laptop with geolocation functionality, even if you don’t 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 did not use it, because it was too lazy to drive another city into my hand (and I travel a lot). The option to automatically determine my coordinates did not work.
The thing is that this gadget is trying to determine your coordinates through the
Windows7 Sensor API . And requires a sensor driver. Recently, preparing a presentation for the Platform 2011, I came across the
Geosense sensor, which very well determines the coordinates. For weather service, they are 100% suitable.
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 at Krasnopresnenskaya using WiFi which was in the hotel. He determined the location with accuracy to the building.
- Likewise, the location was wonderful when I was connected by cable (IP) to ITC.
- In Uglich, I determined the location via WiFi with accuracy to the house
- Now I sit in Sheremetyevo D and again I determined the location with accuracy to the terminal.
Do not forget to only configure this sensor as the default one, since the Orion sensor in Russia, unfortunately, does not work accurately enough.
We determine the coordinates programmatically.
Excuse me, sir, where are we?
-You are in the balloon basket, gentlemen.
Holmes, in a whisper: -Watson, I bet that this person 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:
')
I am now in Sheremetyevo D, connected to the Terminal-D WiFi-Free hotspot and this is what this program returns to me:
Little about security
Of course, in Windows 7 it is possible to set permissions to use this API. If your application is trying to determine the coordinates, a warning will appear:
You can also configure user access:
All calls to the geolocation API are recorded in the log:
Summary
Of course, such geolocation does not replace GPS at all. First of all, because of the accuracy, and sometimes there are mistakes. But it can help out when GPS is not working (in buildings, in conditions of poor signal) and if you have an Internet connection. And as for determining the weather or other contextual services (for example, in social applications) is suitable for sure.
You can download the
source code for a simple console application using the Geolocation API from the MSDN Code Gallery at
code.msdn.microsoft.com/Windows-7-Geolocation-API-25585fac