We fetched the Google Maps API by writing a <script> element in the HTML. But that’s not very nice. It’ll be better to keep the Ajax call inside JavaScript.
This means we need to create a <script> element and add it to the DOM.
The browser will send a JSONP request once the <script> element gets loaded into the DOM. We don’t need the <script> element anymore after this, so let’s remove it.
Let’s say you inserted a wrong API key. Google Maps will tell you that something went wrong.
This isn’t a very nice error message, but there’s nothing we can do about it. If we want to let users see the actual error message, we have to log it into the console.