Hi! I found a way to fix this.
Instead of using that snippet, I used the one implemented in this example and now it works fine. After using that code, another error appeared saying I had to go to https://www.bingmapsportal.com/Application and create a new key. After adding that key, it worked like a charm.
I'm attaching another snippet with how my code looks now in case it's helpful.