Get latitude and longitude with TTMSFNCPlaces

Dear friends, I am using TTMSFNCPlaces to get a close list of results, it works fine, but I have a problem to get the latitude and longitude, as the value is the same in all results in ARequest.Items[I].Coordinate.Latitude.

Best regards, Silvestre

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
  TTMSFNCPlaces1.GetAutoComplete(Edit1.text);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TTMSFNCPlaces1 := TTMSFNCPlaces.Create(Self);
  TTMSFNCPlaces1.OnGetAutoComplete := TMSFNCPlaces1GetAutoComplete;
  TTMSFNCPlaces1.APIKey := '...................';
  TTMSFNCPlaces1.Service := Psgoogle;
  TTMSFNCPlaces1.GetAutoComplete('Mad')
end;

procedure TForm1.TMSFNCPlaces1GetAutoComplete(Sender: TObject;
    const ARequest: TTMSFNCPlacesRequest;
    const ARequestResult: TTMSFNCCloudBaseRequestResult);
  var
    I: Integer;
  begin
    ListBox1.Clear;
    for I := 0 to ARequest.Items.Count - 1 do
    begin
      ListBox1.Items.Add(ARequest.Items[I].Address + ' ' +
        ARequest.Items[I].Coordinate.Latitude.ToString + '-' +
        ARequest.Items[I].Coordinate.Longitude.ToString);
    end;
  end;

Hi,

This behavior is by design. The Google Autocomplete service only returns an address but not a coordinate. So the coordinate always contains the default value.

To get a coordinate you'll need to perform an additional request to SearchByText with the address value. This is a limitation of the Google Autocomplete API which we have no control over.

Alternatively you can consider selecting a different service like Azure or GeoApify which do return coordinates for an AutoComplete request.

Thank you for your quick response, and the alternative solutions.

Happy to help!