Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XE5 Android App with LocationSensor


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Sep 27, 2014 11:44 AM Last Post By: Elli Fal
Maria Hesse

Posts: 9
Registered: 2/4/14
XE5 Android App with LocationSensor  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 19, 2014 8:04 AM
Hi all,

I'm programming with Delphi XE5 FireMonkey for a Android App.
In my code I have the following code:

  procedure TTabbedForm.LocationSensor1LocationChanged(Sender: TObject;const OldLocation, NewLocation: TLocationCoord2D);
var hLat,hLong,h         : String;
    Err                  : Integer;
begin
 LocationSensor1.Active:=false;
 inc(CntPkt);
 SetLength(Pkt,CntPkt);
 Pkt[CntPkt-1].Latitude:=NewLocation.Latitude;
 Pkt[CntPkt-1].Longitude:=NewLocation.Longitude;
 WGS_GK(Pkt[CntPkt-1],Pkt[CntPkt-1].rwGK,Pkt[CntPkt-1].hwGK,ZentralMeridian,Err); {Coordinate transformation}
 str(NewLocation.Latitude:9:6,hLat);
 str(NewLocation.Longitude:9:6,hLong);
 str(CntPkt,h);
 Lbl_CntPkt.Text:=h;
 h:=hLong+', '+hLat;
 Protokoll.Lines.Add('Marker 1');
 PrkSave;
 Lbl_Koord.Text:=h;
 Protokoll.Lines.Add('Marker 2');
 PrkSave;
end;


Sometimes the app crahed. If I check the protocol, I found that it crashed between "Marker 1" and "Marker 2", but why?
If somebody can help me ....

Thanks!
Jason Sweby

Posts: 46
Registered: 5/20/00
Re: XE5 Android App with LocationSensor  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 19, 2014 8:06 AM   in response to: Maria Hesse in response to: Maria Hesse
Perhaps if we knew what was in the PrkSave procedure?
Maria Hesse

Posts: 9
Registered: 2/4/14
Re: XE5 Android App with LocationSensor  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 19, 2014 9:32 AM   in response to: Jason Sweby in response to: Jason Sweby
Jason Sweby wrote:
Perhaps if we knew what was in the PrkSave procedure?

Of cource! I write a protocol in a MemoEdit and in this procedure I save the file:

 procedure TTabbedForm.PrkSave;
var pth,FileN : String;
begin
 pth:=Androidapi.IOUtils.GetExternalFilesDir;
 FileN:=System.IOUtils.TPath.Combine(pth,'protokoll.txt');
 Protokoll.Lines.SaveToFile(FileN);
end;
Elli Fal

Posts: 3
Registered: 10/22/14
Re: XE5 Android App with LocationSensor  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2014 9:50 AM   in response to: Maria Hesse in response to: Maria Hesse
I have seen the same behaviour on XE5....no fix...but a workaround:

do NOT update visible components in the locationchanged section...only put the results into a global variable...and use a timer to take the data from thw variables and update the memo or any other visible coponent there...


Maria Hesse wrote:
Hi all,

I'm programming with Delphi XE5 FireMonkey for a Android App.
In my code I have the following code:

  procedure TTabbedForm.LocationSensor1LocationChanged(Sender: TObject;const OldLocation, NewLocation: TLocationCoord2D);
var hLat,hLong,h         : String;
    Err                  : Integer;
begin
 LocationSensor1.Active:=false;
 inc(CntPkt);
 SetLength(Pkt,CntPkt);
 Pkt[CntPkt-1].Latitude:=NewLocation.Latitude;
 Pkt[CntPkt-1].Longitude:=NewLocation.Longitude;
 WGS_GK(Pkt[CntPkt-1],Pkt[CntPkt-1].rwGK,Pkt[CntPkt-1].hwGK,ZentralMeridian,Err); {Coordinate transformation}
 str(NewLocation.Latitude:9:6,hLat);
 str(NewLocation.Longitude:9:6,hLong);
 str(CntPkt,h);
 Lbl_CntPkt.Text:=h;
 h:=hLong+', '+hLat;
 Protokoll.Lines.Add('Marker 1');
 PrkSave;
 Lbl_Koord.Text:=h;
 Protokoll.Lines.Add('Marker 2');
 PrkSave;
end;


Sometimes the app crahed. If I check the protocol, I found that it crashed between "Marker 1" and "Marker 2", but why?
If somebody can help me ....

Thanks!
Elli Fal

Posts: 3
Registered: 10/22/14
Re: XE5 Android App with LocationSensor  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2014 11:44 AM   in response to: Maria Hesse in response to: Maria Hesse
...
type

TGPSvalues = record
newLAT, newLON, oldLAT, oldLON: double;
newTimeStamp, oldTimeStamp: extended;
newTimeofDay: TDateTime;
Altitude: double;
TrueHeading: double;
SpeedInMetersPerSecond: double;
Manufacturer: string;
TimeStamp: TDateTime;
end;

...

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject; const OldLocation, NewLocation: TLocationCoord2D);
var
AltDbl: double;
TimerService: IFMXTimerService;
begin
// for some weird reason modifying visible elements from here creates unpredictable behaviour on Android device...
// so we just save the data into a record and let the supervisor timer do te rest...

if not TPlatformServices.Current.SupportsPlatformService(IFMXTimerService, IInterface(TimerService)) then
raise EUnsupportedPlatformService.Create('IFMXTimerService');

// as we do not get time stamps here, we can not use the
// old and new positions from the Sensor...so we do it ourselves

// first we save the old position and timestamp:
fGPSvalues.oldLAT := fGPSvalues.newLAT;
fGPSvalues.oldLON := fGPSvalues.newLON;
fGPSvalues.oldTimeStamp := fGPSvalues.newTimeStamp;

// and now we fill in the new one
fGPSvalues.newLAT := NewLocation.Latitude;
fGPSvalues.newLON := NewLocation.Longitude;
fGPSvalues.newTimeofDay := now;

fGPSvalues.newTimeStamp := TimerService.GetTick;

// found this piece of code elsewhere....apparently we do get altitude, heading and speed (in meters/sec)...
{$IFDEF Android}

try
with Sender as TCustomLocationSensor do
begin
fGPSvalues.Altitude := Altitude;
fGPSvalues.TrueHeading := TrueHeading;
fGPSvalues.SpeedInMetersPerSecond := Speed;
end;
except
end;

{$ENDIF}

// Memo1.Lines.Add('State=' + State.ToString());

{ with Sender as TCustomLocationSensor do
begin
AltDbl := Altitude;
Memo1.Lines.add('LAT=' + Latitude.ToString());
Memo1.Lines.add('LON=' + Longitude.ToString());
Memo1.Lines.add('TrueHeading=' + TrueHeading.ToString());
Memo1.Lines.add('Speed=' + speed.ToString());
Memo1.Lines.add('MagneticHeading=' + MagneticHeading.ToString());
Memo1.Lines.add(formatfloat('###0.0## Meters', AltDbl));
end;

with Sender as TCustomSensor do
begin
Memo1.Lines.add('Manufacturer=' + Manufacturer);
Memo1.Lines.add('timestamp=' + timetostr(timestamp));
Memo1.Lines.add('Model=' + MODEL);
// Memo1.Lines.Add('State=' + State.ToString());

end; }

end;

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02