Delphi Xe6 for Android self-control Locationsensor priority using GPS positioning method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.