TGeocoder shows exclusively the address of the first marker

  

Using the method shown below, markers are well drawn on the map. However, the mapGeocoder.GeocodeReverse(coords); always prints exclusively the address of the first marker, not the current one.
Procedure TfrmSijaliceMain.LSLocationChanged(Sender: TObject; const OldLocation,
NewLocation: TLocationCoord2D);
var
CurrentLocation : TMapCoordinate;
MarkerDescriptor : TMapMarkerDescriptor;

coords : TLocationCoord2D;
begin
coords.Latitude := NewLocation.Latitude;
coords.Longitude := NewLocation.Longitude;
CurrentLocation := TMapCoordinate.Create(NewLocation.Latitude, NewLocation.Longitude);
MapView.Location := CurrentLocation;

MarkerDescriptor := TMapMarkerDescriptor.Create(CurrentLocation,
Format(‘Lat: %2.6f, Lng: %2.6f’, [NewLocation.Latitude, NewLocation.Longitude]));

TBGMapMarkers.AddMarker(MapView.AddMarker(MarkerDescriptor));

lblPosition.Text := Format(‘Lat: %2.6f, Lng: %2.6f’,
[NewLocation.Latitude, NewLocation.Longitude]);

if SwitchAddress.IsChecked then
begin
if Not Assigned(mapGeocoder) then
begin

if Assigned(TGeocoder.Current) then
mapGeocoder := TGeocoder.Current.Create;

if Assigned(mapGeocoder) then
mapGeocoder.OnGeocodeReverse := OnGeocodeReverseEventMap;

end;

if Assigned(mapGeocoder) and not mapGeocoder.Geocoding then
mapGeocoder.GeocodeReverse(coords);
end;
end;

The code is used exclusively on Android, and the Delphi version is 10.4.2.
(added)
procedure TfrmSijaliceMain.OnGeocodeReverseEventMap(const Address: TCivicAddress);
begin
LastLocationGeocode := Address;

mmoLastMarkerAddress.Lines.Clear;
mmoLastMarkerAddress.Lines.Add(‘AdminArea: ‘ + Address.AdminArea);
mmoLastMarkerAddress.Lines.Add(‘Thoroughfare: ‘ + UpperCase(Address.Thoroughfare));
mmoLastMarkerAddress.Lines.Add(‘FeatureName: ‘ + UpperCase(Address.FeatureName));
mmoLastMarkerAddress.Lines.Add(‘PostalCode: ‘ + Address.PostalCode);
mmoLastMarkerAddress.Lines.Add(‘SubLocality: ‘ + UpperCase(Address.SubLocality));
mmoLastMarkerAddress.Lines.Add(‘Locality: ‘ + UpperCase(Address.Locality));
mmoLastMarkerAddress.Lines.Add(‘SubAdminArea: ‘ + Address.SubAdminArea);
mmoLastMarkerAddress.Lines.Add(‘CountryCode: ‘ + Address.CountryCode);
mmoLastMarkerAddress.Lines.Add(‘CountryName: ‘ + UpperCase(Address.CountryName));
end;

(added)
TBGMapMarkers is class that contains list of markers.
type
TBGMapMarkers = class
private
class var FBGMapMarkers : TBGMapMarkers;
FMarkers : TList<TMapMarker>;
FMaxCount: Integer;
class function GetMaxCount: Integer; static;
class procedure SetMaxCount(const Value: Integer); static;
class function GetMarkerCount: Integer; static;
class function GetMarker(index: integer): TMapMarker; static;
class procedure SetMarker(index: integer; const Value: TMapMarker); static;
protected
constructor Create;
public
class function Instance: TBGMapMarkers;
class procedure AddMarker(Marker: TMapMarker);

destructor Destroy; override;
class property MaxCount: Integer read GetMaxCount write SetMaxCount;
class property MarkerCount: Integer read GetMarkerCount;
class property Marker[index: integer]: TMapMarker read GetMarker write SetMarker;
end;

implementation

{ TBGMapMarkers }

class procedure TBGMapMarkers.AddMarker(Marker: TMapMarker);
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

if FMarkers.Count = FMaxCount then
begin
FMarkers[0].Remove;
FMarkers.Delete(0);
end;

FMarkers.Add(Marker);
end;

constructor TBGMapMarkers.Create;
begin
inherited;

FMarkers := TList<TMapMarker>.Create;
FMaxCount := 10;
end;

destructor TBGMapMarkers.Destroy;
begin
if Assigned(FMarkers) then
begin
while FMarkers.Count > 0 do
FMarkers[0].Free;

FMarkers.Free;
end;

inherited;
end;

class function TBGMapMarkers.GetMarker(index: integer): TMapMarker;
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

Result := FMarkers[index];
end;

class function TBGMapMarkers.GetMarkerCount: Integer;
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

Result := FMarkers.Count;
end;

class function TBGMapMarkers.GetMaxCount: Integer;
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

Result := FBGMapMarkers.FMaxCount;
end;

class function TBGMapMarkers.Instance: TBGMapMarkers;
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

Result := FBGMapMarkers;
end;

class procedure TBGMapMarkers.SetMarker(index: integer;
const Value: TMapMarker);
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

FMarkers[index] := Value;
end;

class procedure TBGMapMarkers.SetMaxCount(const Value: Integer);
begin
if FBGMapMarkers = nil then
FBGMapMarkers := TBGMapMarkers.Create;

FBGMapMarkers.FMaxCount := Value;
end;

Any suggestion?
Thanks in advance
Bojan

Comments are closed.