2

I want know if the service of geolocation present on Windows 10 is possible be used (by a application) without need install external drivers before (where on Windows 7 seem be mandatory install, based in article of @RRUZ reffered below) and if this service can to retrieve the exact location of a pc (like a precision of a GPS present in any smartphone).

If yes, how i can capture the informations retrieved by the service of location programatically with a Delphi code?

I saw in several sites about how i can discovery this exact location using a Delphi code (but i don't know if this is the right way to retrieve this information programatically in Win 7 ~ Win 10) and i found a code of @RRUZ. So relative to this code, i tested in Windows 7 x64 using a external driver called GPSDirect and i also enabled this driver via Control Panel but when console app is executed is missing some informations:

enter image description here

Code:

program geo;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.TypInfo,
  System.Sensors,
  System.SysUtils;

procedure EnumerateSensors;
var
  LManager : TSensorManager;
  LCustomLocationSensor          : TCustomLocationSensor;
  LCustomLightSensor             : TCustomLightSensor;
  LCustomEnvironmentalSensor     : TCustomEnvironmentalSensor;
  LCustomMotionSensor            : TCustomMotionSensor;
  LCustomOrientationSensor       : TCustomOrientationSensor;
  LCustomMechanicalSensor        : TCustomMechanicalSensor;
  LCustomElectricalSensor        : TCustomElectricalSensor;
  LCustomBiometricSensor         : TCustomBiometricSensor;
  LCustomScannerSensor           : TCustomScannerSensor;
  LSensor  : TCustomSensor;
  i        : Integer;
begin
  LManager := TSensorManager.Current;
  LManager.Activate;
  //LSensors  := LManager.GetSensorsByCategory(TSensorCategory.Location);
  if LManager.Count > 0 then
  for i := 0 to LManager.Count-1 do
  begin
    Writeln(Format('Sensor %d',[i+1]));
    Writeln('--------');

    LSensor:= LManager.Sensors[i];
    Writeln(Format('Category     : %s', [GetEnumName(TypeInfo(TSensorCategory),integer(LSensor.Category))]));
    Writeln(Format('Description  : %s', [LSensor.Description]));
    Writeln(Format('Manufacturer : %s', [LSensor.Manufacturer]));
    Writeln(Format('Model        : %s', [LSensor.Model]));
    Writeln(Format('Serial No    : %s', [LSensor.SerialNo]));
    Writeln(Format('State        : %s', [GetEnumName(TypeInfo(TSensorState),integer(LSensor.State))]));
    Writeln(Format('TimeStamp    : %s', [DatetoStr(LSensor.TimeStamp)]));
    Writeln(Format('Unique ID    : %s', [LSensor.UniqueID]));

    case LSensor.Category of

      TSensorCategory.Location :
      begin
        LCustomLocationSensor:=LSensor as TCustomLocationSensor;
        LCustomLocationSensor.Start;
        Writeln(Format('Sensor Type       : %s', [GetEnumName(TypeInfo(TLocationSensorType),integer(LCustomLocationSensor.SensorType))]));
        Writeln(Format('Authorized        : %s', [GetEnumName(TypeInfo(TAuthorizationType),integer(LCustomLocationSensor.Authorized))]));
        Writeln(Format('Accuracy          : %n', [LCustomLocationSensor.Accuracy]));
        Writeln(Format('Distance          : %n', [LCustomLocationSensor.Distance]));
        Writeln(Format('Power Consumption : %s', [GetEnumName(TypeInfo(TPowerConsumption),integer(LCustomLocationSensor.PowerConsumption))]));
        Writeln(Format('Location Change   : %s', [GetEnumName(TypeInfo(TLocationChangeType),integer(LCustomLocationSensor.LocationChange))]));
        Writeln(Format('Latitude          : %n', [LCustomLocationSensor.Latitude]));
        Writeln(Format('Longitude         : %n', [LCustomLocationSensor.Longitude]));
        Writeln(Format('Longitude         : %n', [LCustomLocationSensor.Longitude]));
        Writeln(Format('Error Radius      : %n', [LCustomLocationSensor.ErrorRadius]));
        Writeln(Format('Altitude          : %n', [LCustomLocationSensor.Altitude]));
        Writeln(Format('Speed             : %n', [LCustomLocationSensor.Speed]));
        Writeln(Format('True Heading      : %n', [LCustomLocationSensor.TrueHeading]));
        Writeln(Format('Magnetic Heading  : %n', [LCustomLocationSensor.MagneticHeading]));
        Writeln(Format('Address1          : %s', [LCustomLocationSensor.Address1]));
        Writeln(Format('Address2          : %s', [LCustomLocationSensor.Address2]));
        Writeln(Format('City              : %s', [LCustomLocationSensor.City]));
        Writeln(Format('State/Province    : %s', [LCustomLocationSensor.StateProvince]));
        Writeln(Format('Postal Code       : %s', [LCustomLocationSensor.PostalCode]));
        Writeln(Format('Country Region    : %s', [LCustomLocationSensor.CountryRegion]));
        LCustomLocationSensor.Stop;
      end;

      TSensorCategory.Light :
      begin
        LCustomLightSensor:=LSensor as TCustomLightSensor;
        Writeln(Format('Lux          : %n', [LCustomLightSensor.Lux]));
        Writeln(Format('Temperature  : %n', [LCustomLightSensor.Temperature]));
        Writeln(Format('Chromacity   : %n', [LCustomLightSensor.Chromacity]));
        Writeln(Format('Sensor Type  : %s', [GetEnumName(TypeInfo(TLightSensorType),integer(LCustomLightSensor.SensorType))]));
      end;

      TSensorCategory.Environmental :
      begin
        LCustomEnvironmentalSensor:= LSensor as TCustomEnvironmentalSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TEnvironmentalSensorType),integer(LCustomEnvironmentalSensor.SensorType))]));
        Writeln(Format('Temperature    : %n', [LCustomEnvironmentalSensor.Temperature]));
        Writeln(Format('Pressure       : %n', [LCustomEnvironmentalSensor.Pressure]));
        Writeln(Format('Humidity       : %n', [LCustomEnvironmentalSensor.Humidity]));
        Writeln(Format('Wind Direction : %n', [LCustomEnvironmentalSensor.WindDirection]));
        Writeln(Format('Wind Speed     : %n', [LCustomEnvironmentalSensor.WindSpeed]));
      end;

      TSensorCategory.Motion :
      begin
        LCustomMotionSensor:= LSensor as TCustomMotionSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TMotionSensorType),integer(LCustomMotionSensor.SensorType))]));
        Writeln(Format('Acceleration X : %n', [LCustomMotionSensor.AccelerationX]));
        Writeln(Format('Acceleration Y : %n', [LCustomMotionSensor.AccelerationY]));
        Writeln(Format('Acceleration Z : %n', [LCustomMotionSensor.AccelerationZ]));
        Writeln(Format('Angle Accel. X : %n', [LCustomMotionSensor.AngleAccelX]));
        Writeln(Format('Angle Accel. Y : %n', [LCustomMotionSensor.AngleAccelY]));
        Writeln(Format('Angle Accel. Z : %n', [LCustomMotionSensor.AngleAccelZ]));
        Writeln(Format('Motion         : %n', [LCustomMotionSensor.Motion]));
        Writeln(Format('Speed          : %n', [LCustomMotionSensor.Speed]));
        Writeln(Format('Update Interval: %n', [LCustomMotionSensor.UpdateInterval]));
      end;

      TSensorCategory.Orientation :
      begin
        LCustomOrientationSensor:= LSensor as TCustomOrientationSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TOrientationSensorType),integer(LCustomOrientationSensor.SensorType))]));
        Writeln(Format('Tilt X         : %n', [LCustomOrientationSensor.TiltX]));
        Writeln(Format('Tilt Y         : %n', [LCustomOrientationSensor.TiltY]));
        Writeln(Format('Tilt Z         : %n', [LCustomOrientationSensor.TiltZ]));
        Writeln(Format('Distance X     : %n', [LCustomOrientationSensor.DistanceX]));
        Writeln(Format('Distance Y     : %n', [LCustomOrientationSensor.DistanceY]));
        Writeln(Format('Distance Z     : %n', [LCustomOrientationSensor.DistanceZ]));
        Writeln(Format('Heading X      : %n', [LCustomOrientationSensor.HeadingX]));
        Writeln(Format('Heading Y      : %n', [LCustomOrientationSensor.HeadingY]));
        Writeln(Format('Heading Z      : %n', [LCustomOrientationSensor.HeadingZ]));
        Writeln(Format('Mag. Heading   : %n', [LCustomOrientationSensor.MagHeading]));
        Writeln(Format('True Heading   : %n', [LCustomOrientationSensor.TrueHeading]));
        Writeln(Format('Comp.Heading   : %n', [LCustomOrientationSensor.CompMagHeading]));
        Writeln(Format('Comp True Head : %n', [LCustomOrientationSensor.CompTrueHeading]));
      end;

      TSensorCategory.Mechanical :
      begin
        LCustomMechanicalSensor:= LSensor as TCustomMechanicalSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TMechanicalSensorType),integer(LCustomMechanicalSensor.SensorType))]));
        Writeln(Format('Switch State   : %s', [BoolToStr(LCustomMechanicalSensor.SwitchState, True)]));
        Writeln(Format('Switch Array State : %d', [LCustomMechanicalSensor.SwitchArrayState]));
        Writeln(Format('Multi Value State  : %n', [LCustomMechanicalSensor.MultiValueState]));
        Writeln(Format('Force              : %n', [LCustomMechanicalSensor.Force]));
        Writeln(Format('Abs. Pressure      : %n', [LCustomMechanicalSensor.AbsPressure]));
        Writeln(Format('Gauge Pressure     : %n', [LCustomMechanicalSensor.GaugePressure]));
        Writeln(Format('Strain             : %n', [LCustomMechanicalSensor.Strain]));
        Writeln(Format('Weight             : %n', [LCustomMechanicalSensor.Weight]));
      end;

      TSensorCategory.Electrical :
      begin
        LCustomElectricalSensor:= LSensor as TCustomElectricalSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TElectricalSensorType),integer(LCustomElectricalSensor.SensorType))]));
        Writeln(Format('Capacitance    : %n', [LCustomElectricalSensor.Capacitance]));
        Writeln(Format('Resistance     : %n', [LCustomElectricalSensor.Resistance]));
        Writeln(Format('Inductance     : %n', [LCustomElectricalSensor.Inductance]));
        Writeln(Format('Current        : %n', [LCustomElectricalSensor.Current]));
        Writeln(Format('Voltage        : %n', [LCustomElectricalSensor.Voltage]));
        Writeln(Format('Power          : %n', [LCustomElectricalSensor.Power]));
      end;

      TSensorCategory.Biometric :
      begin
        LCustomBiometricSensor:= LSensor as TCustomBiometricSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TBiometricSensorType),integer(LCustomBiometricSensor.SensorType))]));
        Writeln(Format('Human Proximity: %n', [LCustomBiometricSensor.HumanProximity]));
        Writeln(Format('Human Presense : %s', [BoolToStr(LCustomBiometricSensor.HumanPresense, True)]));
        Writeln(Format('Touch          : %s', [BoolToStr(LCustomBiometricSensor.Touch, True)]));
      end;

      TSensorCategory.Scanner :
      begin
        LCustomScannerSensor:= LSensor as TCustomScannerSensor;
        Writeln(Format('Sensor Type    : %s', [GetEnumName(TypeInfo(TScannerSensorType),integer(LCustomScannerSensor.SensorType))]));
        Writeln(Format('Human Proximity: %d', [LCustomScannerSensor.RFIDTag]));
        Writeln(Format('Barcode Data   : %s', [LCustomScannerSensor.BarcodeData]));
      end;

    end;
    Writeln;
  end
  else
   Writeln('Not sensors was found');
  LManager.Deactivate;
end;

begin
  try
    EnumerateSensors;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
  • Is this a real GPS sensor? Unusual to find one on a pc. – David Heffernan Mar 07 '18 at 07:52
  • 1
    PCs aren't usually equipped with GPS, no. But geolocation doesn't use just GPS alone, it also uses info about known WiFi hotspots and such, too. Web browsers in laptops use WiFi-based geolocation, for instance – Remy Lebeau Mar 07 '18 at 08:27
  • 2
    Which is my point. If you want GPS like precision you need a GPS sensor. Do you have one? – David Heffernan Mar 07 '18 at 08:47
  • @DavidHeffernan, yes seem that this code of RRUZ works only with a GPS sensor installed. But like Remy said exist browsers in laptops that use WiFi-based geolocation, provabebly like [this](https://www.maps.ie/coordinates.html) where the user can be located based in coordinates. I searched something similar and found [this example](http://csharphelper.com/blog/2016/05/use-the-location-api-to-find-the-computers-latitude-and-longitude-in-c/) in C#, but still nothing referente in Delphi. –  Mar 07 '18 at 12:13
  • I found [this example](https://www.experts-exchange.com/questions/28279575/Using-Microsoft-Location-api-locationapi-dll-in-Delphi-5.html) in Delphi using [**Location api**](https://msdn.microsoft.com/pt-br/library/windows/desktop/dd464636(v=vs.85).aspx), but unfortunately also is mandatory a GPS sensor installed to works. –  Mar 07 '18 at 12:18
  • As I read the question, you would like to have the location provided with the same accuracy as you get from a GPS sensor. Is that a correct reading of the question? I'm looking at the part where you said, *"retrieve the exact location of a PC like a precision of a GPS present in any smartphone"* – David Heffernan Mar 07 '18 at 12:25
  • @DavidHeffernan, yes and browsers are able to this and also [applications](http://csharphelper.com/blog/2016/05/display-google-maps-computers-location-c/). Even if is not exist a GPS installed like Remy Lebeau said before. But what i can use in Delphi to gain these infos? –  Mar 07 '18 at 12:29
  • I think you are asking for the impossible. You can't expect the same accuracy as a GPS. – David Heffernan Mar 07 '18 at 12:32
  • @DavidHeffernan,ok and how the browsers said my exact location on map without know if a have a GPS installed on pc or no? How this works? see the site posted in my previous comment, click to find your coordinates and you will be your exact location ;-) –  Mar 07 '18 at 12:35
  • Relative to C# example i not sure but seem that is used the service of geolocation installed on Windows 10 (video posted in my question). I tested in my Windows 7 and not worked. –  Mar 07 '18 at 12:37
  • No, they can't do this to the same accuracy. For instance, Google maps has me about 300m from where I actually am. Ask yourself how it could possibly be as accurate as GPS. – David Heffernan Mar 07 '18 at 12:41
  • @DavidHeffernan, i tested and here is showed my exact location on map. You have extended the map? (Zoom +) :-) –  Mar 07 '18 at 12:46
  • @coyote The site you've linked to is using [Google's geolocation API](https://developers.google.com/maps/documentation/geolocation/intro). This can provide an estimate of the user's location with varying degrees of success and accuracy. In your case it appears to have been quite accurate but in other cases it is not. If that's what you are looking for then this is off topic being a simple ask for a library or tutorial. – J... Mar 07 '18 at 12:46
  • @J..., then based in my conclusion the service of geolocation installed in Windows 10 (video linked in my question) works similar to site linked? These C# examples showed in my comments seem use this service. –  Mar 07 '18 at 12:51
  • @coyote Yes, similarly. David's point stands, however. You cannot reliably get GPS accuracy without a GPS sensor. The windows API [provides some guidelines](https://learn.microsoft.com/en-us/uwp/api/Windows.Devices.Geolocation). GPS will give 10 meter accuracy. Wifi can put you within 30-500 meters of the correct location, but even then there will be exceptions, particularly as you get away from populated centers. Once you're into cell towers and IP addresses the accuracy can drop to several kilometers. – J... Mar 07 '18 at 12:55
  • Good for you. Presumably Google is using your phone's GPS. Try using an incognito window and see how it does. Try in different locations. How do you explain my results? Ask yourself how you could get GPS accuracy without a GPS device. Try to understand the technology. Don't just gather one data point that you don't understand and extrapolate wildly. – David Heffernan Mar 07 '18 at 12:56
  • @DavidHeffernan, i'm not using my phone to test the linked site, i tested in my pc that not have any GPS installed. And location was gived with 100% precision (in my case). But even so i will follow yours advices. –  Mar 07 '18 at 13:11
  • Google knows who you are and where your phone is. So even when you use your PC it gives you info based on where you phone is. Go to Google maps and see for yourself. Try with an incognito window using a variety of networks and see how it fares. – David Heffernan Mar 07 '18 at 13:17
  • Even that these C# examples linked in my comment not are with accurancy this can be useful in others situations, i'm sad because not found any example in Delphi similar that can works at least on Windows 10 (like these C# examples works) without need have a GPS sensor installed. –  Mar 07 '18 at 14:24
  • @coyote You have the link to two APIs that can do this. You don't need an example, you just need to read the documentation and use them. If you have a more specific problem relating to that task please [edit] your question to something more detailed. – J... Mar 07 '18 at 15:27
  • @J..., both Delphi examples that i lined need of a GPS sensor installed. The C# example (in Windows 10) not is necessary to works. The Delphi examples uses specific apis to administrate sensors and C# examples uses a different api where not is necessary have a sensor installed on pc to work. –  Mar 07 '18 at 16:00
  • Nobody is going to answer the question in its current t form because you are asking for GPS precision without a GPS. Which is impossible. – David Heffernan Mar 07 '18 at 17:41
  • And even if the question is reworded, it's still looking for a tutorial. You have the C# code, if you want to use the Win10 or the Google APIs you know where they are, you have the documentatio - what is the problem? If you want help using those APIs in Delphi then ask that question instead. – J... Mar 07 '18 at 19:21
  • @J..., OK, thank by help and advice. I think that i really must make this (try use these apis on Delphi, and in case of failure, back here again). –  Mar 07 '18 at 21:15

0 Answers0