Can't find DWFusedLocationClientDelegate

AAaaaagh! Thanks! I have grown sio used to no longer requiring the permissions code in later androids, where it all has to be done manually by the user for every priogramme, that I have taken it out of my programmes! In later androids, if you have not set up permissions, you get an error message telling you to set the permissions if you haven’t. Not so in earlier ones.

Any commentii on the other 2 oddities?

It’s because in this code:

procedure tLocMainForm.ButtonStopClick(Sender: TObject);
begin
   if FFusedLocation.IsActive then FFusedLocation.Stop(true);
end;

You’re calling Stop with the ANoCallback parameter as true. Doing so results in no callback to LocationUpdatesChange. It was designed this way to prevent a crash when calling Stop when the application is terminating. Calling Stop with no parameter defaults ANoCallback to False, thus LocationUpdatesChange will be called.

The other oddity occurs because of this design. Since LocationUpdatesChange is never called when ANoCallback is True, the IsActive flag is not updated - and it’s not supposed to be, because it’s expected that the app will be terminating.

So you can’t turn the GPS on or off if desired. OK.

Then the last oddity (I hope):
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
,exit, (as above)
Stop;
if FFusedLocation <> nil then FFusedLocation.Free;
inherited;
end;

You absolutely can. Calling Stop with no parameters (equivalent to: Stop(False)) turns off location updates. Calling Start starts it again.

I can take a look later if you have not already solved it by then.

If you change the FFusedLocation variable to the type: IFusedLocation (instead of TFusedLocation), and remove the call:

FFusedLocation.Free; 

(since it’ll free automatically since the type is now an interface) the “crash” should disappear.

Also, with this code:

if FFusedLocation.IsActive then FFusedLocation.Stop(true);

Checking IsActive is not necessary, as the call to Stop already checks if it is active

Bewdy, Newk! - as the ancient tennis players used to say.

Whoops - I will now edit this, as what I put in was inaccurate.

While you are waiting for a GPS fix (either initially, or if you go into a sheltered area), how do you tell whether the GPS is providing sensible data? Is it just by using the accuracy and ignoring things if it is excessive, or is there a sort of GPSOutOfRange anywhere please?

If you press Stop, GPS activity ceases, and RequestLastKnownLocation continues to give you the same location when you use it (fine!). When you press Start after a Stop, it does not restart on the first press. When you press Start a second time, it turns back on and functions normally. You can’t just put in 2 Starts in a row in the ButtonStart.Click routine - this does not work. Even if you put a sleep(1000) with a couple of ApplicationProcessMessages around it, it does not properly restart the GPS system.

1 Like