InputPlace can be linked to a Google Map to control the map from the selected place. Based on Google Places AutoComplete by Google.
Link the InputPlace to a Google Map to control the map with the onplacechanged callback. Do not forget to include the <script> with your Google API Key.
<div class="card">
<h5>Linked Map</h5>
<p>Link the InputPlace to a Google Map to control the map with the <code>onplacechanged</code> callback. Do not forget to include the <code><script></code> with your <strong>Google API Key</strong>.</p>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCvCDkYieuUBmMWon_mfLAfjuaeuosuqow&libraries=places"></script>
<script>
function updateMap(place) {
const map = PF('googleMap').getMap();
if (!map || !place.geometry) {
return;
}
// drop a pin
const marker = new google.maps.Marker({
map,
position: place.geometry.location,
});
// If the place has a geometry, then present it on a map.
map.panTo(place.geometry.location);
map.setZoom(17);
}
</script>
<h:form id="formMapUsage">
<p:growl id="growl" showDetail="true" showSummary="true" globalOnly="false"/>
<div jsf:id="inputGroup" class="field grid">
<div class="col-12">
<div class="p-inputgroup mb-4">
<div class="p-inputgroup-addon"><i class="fa-solid fa-location-dot"></i></div>
<pe:inputPlace widgetVar="place" placeholder="Enter a location" styleClass="w-full" onplacechanged="updateMap(place)"/>
</div>
</div>
<div class="col-12">
<p:gmap widgetVar="googleMap" center="41.381542, 2.122893" zoom="15" type="ROADMAP" style="width:100%;height:400px"/>
</div>
</div>
</h:form>
</div>