我创建了一个带有自动完成谷歌位置 API 输入和功能的树枝。现在我需要将 place 变量与我的 php 控制器中接收到的数据一起使用,但我不知道我是如何做到的。我用过easyadmin 3和symfony 5。有人可以帮助我吗?谢谢!
{% form_theme form 'form/form_theme.html.twig' %}
{% block address_form_widget %}
<script>
let autocomplete;
function initAutocomplete()
{
autocomplete = new google.maps.places.Autocomplete(
document.getElementById('autocomplete'),
{
types: ['establishment'],
componentRestrictions: {'country' : ['ES']},
fields: ['place_id', 'geometry', 'name']
}
);
autocomplete.addListener('place_changed', onPlaceChanged);
}
function onPlaceChanged()
{
var place = autocomplete.getPlace();
if(!place.geometry)
{
document.getElementById('autocomplete').placeholder = 'Enter a place';
} else {
place = place.name . place.geometry;
document.getElementById('details').innerHTML = place;
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=myApiKeyHere&libraries=places&callback=initAutocomplete" async defer></script>
{% endblock %}