Good day!
I am trying to write a programm that receives geo coordinates from TLocationSensor, but it can't find any location sensor. Code sample:
procedure TForm1.Button2Click(Sender: TObject);
var
MyLocationSensorArray : TSensorArray;
MyLocationSensor : TCustomLocationSensor;
begin
try
TSensorManager.Current.Activate;
MyLocationSensorArray := TSensorManager.Current.GetSensorsByCategory(TSensorCategory.Location);
if MyLocationSensorArray <> nil then begin
Memo1.Lines.Add('Location Sensor Found');
MyLocationSensor := MyLocationSensorArray[0] as TCustomLocationSensor;
MyLocationSensor.Start;
Memo1.Lines.Add('Latitude = '+ FloatToStr(MyLocationSensor.Latitude));
Memo1.Lines.Add('Longitude = '+ FloatToStr(MyLocationSensor.Longitude));
MyLocationSensor.Stop;
// ShellExecute(handle,'open',PChar(Format(GoogleMapsURL,
// [MyLocationSensor.Latitude.ToString, MyLocationSensor.Longitude.ToString])),
// '','',SW_SHOWNORMAL);
end
else
begin
Memo1.Lines.Add('Location Sensor Not Found!')
end;
finally
TSensorManager.Current.DeActivate // deactivate sensor manager
end;
end;
Programm is running on tablet with Windows 10 Lenovo MIIX 320-10ICR. GPS is working, there is a internal maps app and it shows my position correctly. Also I've checked location sensor with Sensor Diagnostic Tool from Windows Kits 10, here is a screen
I've tried to list all available sensors
procedure TForm1.Button3Click(Sender: TObject);
var
i : integer;
NumberOfSensors : integer;
begin
// get list of found sensors - if any
TSensorManager.Current.Active := true;
NumberofSensors := TSensorManager.Current.Count;
Memo1.Lines.Add('Sensors: '+IntToStr(NumberOfSensors));
Memo1.Lines.Clear;
if NumberOfSensors = 0 then
Memo1.Lines.Add('No Sensors Found')
else
for i := 0 to NumberOfSensors-1 do begin
Memo1.Lines.Add(
IntToStr(i)
+ ': '
+ TSensorManager.Current.Sensors
.Name
+ '", Category: '
+ GetEnumName(System.TypeInfo(TSensorCategory),
Ord(TSensorManager.Current.Sensors.Category))
);
end;
TSensorManager.Current.Active := false;
end;
And here is a result
0: BMA25X", Category: Motion
1: Simple device orientation service - Simple device orientation sensor (Microsoft)", Category: Orientation
What is wrong? This app worked well on another tablet with Windows 8.