Select delivery address

In this example, an address will be selected and the fields below it will be filled with the address information.

Example: Select delivery address

Codeexample: Select delivery address

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Example | Select delivery address</title>
	<style>
	:root {
		--smartmaps-boxshadow: 0 0 0 rgba(0, 0, 0, 0);
	}
	</style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col">
                <form>
                    <input id="ac" class="sm-search" type="search" placeholder="Adresse suchen" value="" style="width: 400px;">
                    <br><br><br>
                    <div class="input-group input-group-sm mb-3">
                        <span class="input-group-text">Straße</span>
                        <input id="street" class="form-control">
                        <span class="input-group-text">Hausnummer</span>
                        <input id="houseNo" class="form-control">
                    </div>
                    <div class="input-group input-group-sm mb-3">
                        <span class="input-group-text">PLZ</span>
                        <input id="zip" class="form-control" >
                        <span class="input-group-text">Stadt</span>
                        <input id="city" class="form-control">
                    </div>
                    <div class="input-group input-group-sm mb-3">
                        <span class="input-group-text">Bundesland</span>
                        <input id="state" class="form-control">
                        <span class="input-group-text">Land</span>
                        <input id="country" class="form-control">
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script
        src="https://www.yellowmap.de/api_rst/api/loader?libraries=free-3,autocomplete-5&apiKey={API_KEY}"></script>

    <script>
        ym.ready({ autocomplete: 5 }, function (modules) {
            var autoComplete = modules.autoComplete('#ac', {
                isoCountries: [],
                includeFilters: {
                    street: true
                },
                dataType: 'json'
            });

            autoComplete.on('selected', function (geojson, address, query) {
                console.log(address)
                document.getElementById("street").value = address.street ? address.street : "" ;
                document.getElementById("houseNo").value = address.houseNo? address.houseNo: "";
                document.getElementById("zip").value = address.zip? address.zip: "";
                document.getElementById("city").value = address.city? address.city: "";
                document.getElementById("country").value = address.countryLongName? address.countryLongName: "";
                document.getElementById("state").value = address.state? address.state: "";

            });
        });
    </script>
</body>
</html>