Print Page | Close Window

TMSFMXWebGMapsReverseGeocoding android sensor

Printed From: TMS Software
Category: FMX Components
Forum Name: FMX WebGMaps / WebOSMaps
Forum Discription:
URL: http://www.tmssoftware.com/site/forum/forum_posts.asp?TID=7013
Printed Date: 19 Jan 2020 at 11:41am


Topic: TMSFMXWebGMapsReverseGeocoding android sensor
Posted By: Camacho Chacon Hilda
Subject: TMSFMXWebGMapsReverseGeocoding android sensor
Date Posted: 26 Sep 2016 at 6:02pm
Hi guys , when i use the code below and I invoke   TMSFMXWebGMapsReverseGeocoding1.LaunchReverseGeocoding with andorind

  procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
    const OldLocation, NewLocation: TLocationCoord2D);
  var
    LDecSeparator: String;
  begin
    try
      LDecSeparator := FormatSettings.DecimalSeparator;
      FormatSettings.DecimalSeparator := '.';
      if FCurrentPosition.Distance(NewLocation) > Accuracy then
      begin
        FCurrentPosition := NewLocation;

        latmap := NewLocation.Latitude;
        Longmap := NewLocation.Longitude;

        if ((latmap >= -90) and (latmap <= 90)) and
          ((Longmap >= -180) and (Longmap <= 180)) then
        begin
          cp := '0';
          try

            TMSFMXWebGMapsReverseGeocoding1.Latitude := latmap;
            TMSFMXWebGMapsReverseGeocoding1.Longitude := Longmap;
            TMSFMXWebGMapsReverseGeocoding1.LaunchReverseGeocoding;   <------
            cp := (TMSFMXWebGMapsReverseGeocoding1.ResultAddress.PostalCode);

          except
            cp := '0';
          end;
        end
        else
          showmessage('GPS error, location not found');
      end;
    finally
      LocationSensor1.Active := False;
    end;
  end;

 I get the next error



  procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
    const OldLocation, NewLocation: TLocationCoord2D);
  var
    LDecSeparator: String;
  begin
    try
      LDecSeparator := FormatSettings.DecimalSeparator;
      FormatSettings.DecimalSeparator := '.';
      if FCurrentPosition.Distance(NewLocation) > Accuracy then
      begin
        FCurrentPosition := NewLocation;

        latmap := NewLocation.Latitude;
        Longmap := NewLocation.Longitude;

        if ((latmap >= -90) and (latmap <= 90)) and
          ((Longmap >= -180) and (Longmap <= 180)) then
        begin
          cp := '0';
          try

            TMSFMXWebGMapsReverseGeocoding1.Latitude := latmap;
            TMSFMXWebGMapsReverseGeocoding1.Longitude := Longmap;
            TMSFMXWebGMapsReverseGeocoding1.LaunchReverseGeocoding;
            cp := (TMSFMXWebGMapsReverseGeocoding1.ResultAddress.PostalCode);

          except
            cp := '0';
          end;
        end
        else
          showmessage('GPS error, location not found');
      end;
    finally
      LocationSensor1.Active := False;
    end;
  end;



can I help you?



Replies:
Posted By: Camacho Chacon Hilda
Date Posted: 26 Sep 2016 at 6:02pm


Posted By: Camacho Chacon Hilda
Date Posted: 26 Sep 2016 at 6:03pm
Sorry this is the error

---------------------------
Debugger Exception Notification
---------------------------
Project UBSPA.apk raised exception class EJNIException with message 'android.os.NetworkOnMainThreadException'.
---------------------------
Break   Continue   Help   
---------------------------


Posted By: Pieter Scheldeman
Date Posted: 27 Sep 2016 at 8:43am
Hi, 

You are launching the reverse geocoding from within a different thread, please use the following code to thread queue the code and avoid the exception.

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
  const OldLocation, NewLocation: TLocationCoord2D);
begin
  TThread.Queue(nil,
  procedure
  var
    cp: String;
  begin
    TMSFMXWebGMapsReverseGeocoding1.Latitude := NewLocation.Latitude;
    TMSFMXWebGMapsReverseGeocoding1.Longitude := NewLocation.Longitude;
    TMSFMXWebGMapsReverseGeocoding1.LaunchReverseGeocoding;
    cp := TMSFMXWebGMapsReverseGeocoding1.ResultAddress.PostalCode;
  end
  );
end;


Posted By: camacho hilda
Date Posted: 27 Sep 2016 at 7:41pm
Thanks , it work



Print Page | Close Window