However, this generated an error that google.maps.places is undefined. From the page source code, it looks like Anvil is loading the Geometry library, but not Places. So I tried adding the following to the Native Libraries file (with my key filled in):
But then got back the error “You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.” and lots of javascript errors in the console. So it looks like loading the Places library is conflicting with what Anvil loads by default.
Any ideas on what I am doing wrong or how to get this to work?
I made a simplified app that just has a single text input and demonstrates the above issue. Check Native libraries to see the javascript code and Form1/address_box_show to see how the javascript is applied to an input text field.
Yes, thank you for the response. Although I think it would not matter here, because if that was the only issue I would get a quota error from Anvil’s built-in Google Maps API key.
Instead I am getting an error that Anvil is incorporating a Google Maps JavaScript library, but not the one I need. And when I manually incorporate the one I need, it results in errors.
from anvil.js.window import google
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
google.maps.places.Autocomplete(anvil.js.get_dom_node(self.address_box))
Adding the “defer” keyword works! Thanks for the quick response on a Saturday night/Sunday morning. I also deleted the Google API service entirely on the Anvil gui, and that may help avoid conflicts.
Will try moving the javascript code to python in the morning. That will make it easier to keep track of.
@benny thanks for the example.
I was able to get mine to work as well. But my autocomplete returns the country abbreviation instead of the full country name.
E.g. Manchester, UK instead of Manchester, United Kingdom
I need the complete name. Do you know how to change this.
At the time of writing this I wasn’t able to find a solution
I have not looked at that. One option would be to take the autocomplete address and send it to the Google Geocode or Places API to get more details, including full country name: