If using Xe6 's own Locationsensor control, the default priority is to use the network location, the network location accuracy is not accurate, can not meet the requirements of high-precision positioning. However, the Xe6-locationsensor control can not specify the network location first or GPS positioning priority, if the call Java API can be specified priority to use GPS positioning, the following code has been verified by the actual GPS positioning may be directly assigned. uses Androidapi.JNI.Location, Androidapi.jnibridge, androidapi.jni.javatypes, ANDROIDAPI.JNI.OS,FMX. helpers.android,androidapi.jni.graphicscontentviewtext; type Tlocationlistener = class; TForm1 = Class (Tform) ... private {private declarations} Flocationmanager:jlocationmanager; locationlistener:tlocationlistener; public destructor Destroy; override; {Public Declarations} procedure onlocationchanged (location:jlocation ); end; //sensore gps Tlocationlistener = Class (Tjavalocal, Jlocationlistener) private & nbsp; [weak] fparent:tform1; public Constructor Create (AParent: TFORM1); procedure onlocationchanged (location:jlocation); cdecl; procedure onproviderdisabled (provider:jstring); cdecl; procedure onproviderenabled (provider:jstring); cdecl; procedure onstatuschanged (provider:jstring; status:integer; extras:jbundle); cdecl; end; constructor tlocationlistener.create (Aparent:tform1);begin inherited create; fparent: = Aparent;end; procedure tlocationlistener.onlocationchanged (location:jlocation); begin Fparent.onlocationchanged (location), End; procedure tlocationlistener.onproviderdisabled (provider: jstring); beginend; procedure tlocationlistener.onproviderenabled (provider:jstring);beginend; Procedure tlocationlistener.onstatuschanged (provider:jstring; status:integer; extras:jbundle);beginend; destructor tform1.destroy;begin if Assigned (Locationlistener) then Flocationmanager.removeupdates (LOCationlistener); inherited;end; procedure tform1.onlocationchanged (location:jlocation);//When the position is changed, display the warp, Latitude begin if Assigned (location) then begin //variabili da recuperare dal sensore label4.text: = location.getlatitude.tostring; Label5.text: = location.getlongitude.tostring; Label6.text: = location.getaltitude.tostring; label8.text: = location.getspeed.tostring; Label10.text: = location.gettime.tostring; end;end; procedure tform1.formcreate (sender:tobject); var locationmanagerservice:jobject; location:jlocation;begin if not Assigned (FLocationManager) then begin Locationmanagerservice: = Sharedactivitycontext.getsystemservice ( TJContext.JavaClass.LOCATION_SERVICE); Flocationmanager: = Tjlocationmanager.wrap (( Locationmanagerservice as Ilocalobject). Getobjectid); if not Assigned (Locationlistener) then Locationlistener: = Tlocationlistener.create ( Self); flocationmanager.requestlocationupdates (TJLocationManager.JavaClass.GPS_PROVIDER, 1000, 0, Locationlistener, TJLooper.JavaClass.getMainLooper); //Monitor status //binding monitoring, with 4 parameters //Parameter 1, equipment: There are gps_provider and network_provider two kinds //Parameter 2, Location update period, unit milliseconds //Parameter 3, Position change minimum distance: When the location distance changes beyond this value, the location information is updated //Parameter 4, monitoring //Remarks: Parameters 2 and 3, if the parameter 3 is not 0, the parameter 3 is the same, the parameter 3 is 0, then the time is updated periodically. ; 0, refresh at any time /1 seconds update, or minimum displacement change more than 1 meters update once; // Note: The update accuracy is very low here, it is recommended to start a thread in the service, Sleep (10000) in run, then execute Handler.sendmessage (), update location end; Flocationmanager.isproviderenabled (TJLocationManager.JavaClass.GPS_PROVIDER); Flocationmanager.isproviderenabled (TJLocationManager.JavaClass.NETWORK_PROVIDER); onlocationchanged (location); end
Delphi Xe6 method of calling Java GPS