'livewire form's google place picker is resseting alone

I am using jquery to get google maps places and the lat lng.when i click in another input, the place and lat lng input are resetted and i dont know why. Here is the html code:

<div class="row">
              <div class="col-md-6">
              <div class="form-group">
                   <label for="user.location" class="form-control-label">Adresse du lieu</label>
                    <input class=" form-control" placeholder="Entrer l'adresse du lieu" id="adresse"
                                        name="adresse" wire:model="adresse" />
                                </div>
                            </div>
                      <div class="col-md-6">
                       <div class="form-group">
                       <label for="user" class="form-control-label">Zip/Code postal</label>
                        <input class="form-control" type="text" placeholder="Zip/Code postal" name="codepostal"  wire:model="codepostal">
                                    
                        </div>
                       </div>
    
    
                        </div>

and here is the js code

<script>
    

var searchInput = 'adresse';

$(document).ready(function () {
    var autocomplete;
    autocomplete = new google.maps.places.Autocomplete((document.getElementById(searchInput)), {
        types: ['geocode'],
        componentRestrictions: {
    }
    });
    
    google.maps.event.addListener(autocomplete, 'place_changed', function () {
        var near_place = autocomplete.getPlace();
        document.getElementById('latitude').value = near_place.geometry.location.lat();
        document.getElementById('longitude').value = near_place.geometry.location.lng();
        document.getElementById('adresse').value = near_place.formatted_address;
    });

    $(document).on('change', '#'+searchInput, function () {
        $("#adresse").attr("readonly", true);
    document.getElementById('latitude').value = '';
    document.getElementById('longitude').value = '';
    
});
});
</script>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source