Win32 Native(api or anything) to read current machine Geolocation?
Asked Answered
C

1

11

Did anyone manage to read a Windows machine's longtitude & latitude (GPS Position), without using .Net 4 libraries (Windows.Devices namespace) nor Javascript or other webbish code ?

There must be a native way. The location sensor is in the Control Panel,

I could not find any API nor valid documentation which allows me to read off of it, I would like to avoid having Net framework 4.0 as a dependency and invoking a browser process in the background, just to read current user's location via javascript is a huge overhead in my opinion

Caesar answered 3/4, 2016 at 14:15 Comment(13)
Windows.Devices.Geolocation namespace in the Windows Runtime.Rink
@Rink the question is bout avoiding Windows.DevicesEpos
msdn.microsoft.com/en-us/library/windows/desktop/…Cadmar
@HansPassant that should be posted as an answer.Magree
I'm sure the OP can take care of that. Or anybody else.Cadmar
@Ilya: No, not really. The question is about avoiding the .NET framework. The Windows.Devices.Geolocation namespace is accessible from native code, without a dependency on .NET. It can also be consumed by C# code, but that's besides the point.Rink
@Rink but .NET lib has to be available on the target PC, right ? So that a dependency ..?Epos
I don't think there's a native way, you need 3th part libraries. Remember Win32 API is more about comunicating between the operative system and the user. Also don't mix GPS with time zones, the last is the one appeared in the Control Panel.Aldoaldol
@Ilya: Those are Windows Runtime components, not .NET assemblies. You don't need .NET to access Windows Runtime components, but they are accessible from .NET or JavaScript as well.Rink
@Rink but does it work on, say, windows 7 ?Epos
@Epos You are confusing Windows.* (Windows Runtime) with System.* (.NET Framework).Polyclinic
@RaymondChen I'm just quoting the OP. But yes, the relationship between WRT .NET and Win32 is confusing.Epos
@ilya A web search for geolocation windows 7 turned up the C# sample, but it had a link at the bottom to the sensor API. Looks like you want SENSOR_CATEGORY_LOCATION.Polyclinic
P
4

The native Win32 API is the Sensor API. The Sensor API Programming Guide has some fairly detailed C++ examples.

Good article: Using Windows 7 Location API

(Google the above terms if the links ever break).

Philistine answered 3/4, 2016 at 14:15 Comment(1)
MSVC now gives out deprecation warnings from the COM based Location API. Users are pushed to use Windows.Devices. Much of the new API is marked with DualApiPartitionAttribute so they can be used from WIN32 apps as well as UWP.Importunacy

© 2022 - 2024 — McMap. All rights reserved.