The Delphi Xe6 for Android Locationsensor control defaults to the use of network positioning, the application of high positioning accuracy requires that we can modify the original code to directly specify the GPS location.
Modification Method:
Copy the C:\Program Files\embarcadero\studio\14.0\source\rtl\common\system.android.sensors.pas to your project directory
Open System.Android.Sensors.pas to find function TUIAndroidLocationSensor.DoStart:Boolean, and then follow the instructions below to modify it.
function TUIAndroidLocationSensor.DoStart:Boolean;
Var
providername:jstring;
Provider:jlocationprovider;
Begin
Result: = False;
fpermitted: = tpermission.ispermitted (stringtojstring (' Android.permission.ACCESS_FINE_LOCATION '));
If Fpermitted Then
Begin
If not Assigned (Flocationlistener) Then
Flocationlistener: = Tlocationlistener.create (self);
{-----Delete the following lines
If flocationmanager.isproviderenabled (TJLocationManager.JavaClass.NETWORK_PROVIDER) Then
ProviderName: = TJLocationManager.JavaClass.NETWORK_PROVIDER
Else
If flocationmanager.isproviderenabled (TJLocationManager.JavaClass.GPS_PROVIDER) Then
ProviderName: = TJLocationManager.JavaClass.GPS_PROVIDER
Else
ProviderName: = TJLocationManager.JavaClass.PASSIVE_PROVIDER;
-----Delete the above lines}
ProviderName: = TJLocationManager.JavaClass.GPS_PROVIDER;//Add this line
Provider: = Flocationmanager.getprovider (ProviderName);
If Assigned (Provider) Then
Begin
Fmyrunner: = Tlocationrunnable.create (Flocationmanager, Flocationlistener, ProviderName);
Factivity.runonuithread (Fmyrunner);
Result: = True;
End
End
End
Delphi Xe6 for Android self-control Locationsensor priority using GPS positioning method