Still struggling with location stuff. I have taken DW.Loaction.FusedLocation.Android
and put it into a programme. Unfortunately I am getting the error below:
Error:
Crashes with EJNI fatal error
Java Type com/delphiworlds/kastri/DWFusedLocationClientDelegate could not be found.
(even though it’s in the source file)
begin
LocationManagerService := tAndroidHelper.Context.getSystemService(
TJContext.JavaClass.LOCATION_SERVICE);
FLocationManager := TJLocationManager.Wrap(
(LocationManagerService as ILocalObject).GetObjectID);
fLocationManager.addNmeaListener(Lis);
it wants Lis to be a JGpsStatus_NmeaListener, not a tGpsStatus_NmeaListener.
But if I put tGpsStatus_NmeaListener there, I cannot work out how to get it to
connect to my LocationManager (ie make it possible to use the routine
procedure NmeaListen(timestamp : int64; NmeaMessage : jString);
Dear Everyone,
I am still having the agonies of the damned trying to make some sense out of location stuff. Here is the latest contribution, using DW.FusedLocationAndroid. It compiles OK, loads OK, instals OK, then dies with “Java type com\delphiworlds/kastri/DWFusedLocationClient could not be found.”
I spent 7 hours with ChatGPT trying to sore it out. It kept talling me that I needed a Kastri.aar. I worked through multiple things Android Studio, and every suggestion failed until ChatGPT crashed at the end of it!
app\android64\debug:
androidlibrarymanifest.txt
androidmanifest.xml (betting on this one? - and if so, will there be an android32 one similarly?)
androidmanifest-merged.xml
manifestgenerationpropertylist.txt
manifestmergepropertylist.txt
The interval is for when the location actually changes, i.e. if the device is moving. If the device is not moving, does your app need to report the same location every 1000ms? If so, save the value, and use a timer.
The RequestLastKnownLocation seems to to the job fine, with a timer.
When the programme terminates, an error occurs.
If I leave this destructor in, I get a pointer error.
If I just put “exit” in before the “Stop”, I get an access violation accessing address 8
Neither of these is a disaster, as the programme terminates anyway, but it is odd and untidy.
destructor tLocMainForm.Destroy;
begin
Stop;
if FFusedLocation <> nil then FFusedLocation.Free;
inherited;
end;
Just to give you the rationale:
One of the aims of the programme will be to track paths. With the defaults, or with the intervals set to 1000 each and the minimum distance set to 0, it takes about 20 to 30 metres to get the next location update. A lot can happen in 30 metres! Hence my interest in getting 1 second updates.
Another oddity:
If you use Start, then LocationUpdatesChange occurs with AActive true.
If then you use Stop, you get no LocationUpdatesChange, and RequestLastKnownLocation continues to give the same last location details (makes sense).
If you then press Start, you get 2 LocationUpdatesChange, both with AActive false, and it remains stopped.
If you again press Start, get a LocationUpdatesChange with AActive true, and it runs ok.
(But if you put “if not FFusedLocation.IsActive then Start” this doesn’t work either. You have to wait and push the button again.)
It would not be working on any version of Android above version 6, since your code does not request the relevant runtime permissions. Add System.Permissions to the uses clause and change the code in ButtonStartClick to:
procedure tLocMainForm.ButtonStartClick(Sender: TObject);
begin
PermissionsService.RequestPermissions(['android.permission.ACCESS_FINE_LOCATION'],
procedure(const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray)
begin
if AGrantResults[0] = TPermissionStatus.Granted then
Start;
end
);
end;