[Python] How to limit google maps auto complete to only one country?

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have tried everything so my search input only gives autocomplete options from only Dominican Republic but I have not been able to achieve it, anyone here knows how to do this?


    <input
    type="text"
    id="searchInput"
    class="form-control"
    placeholder="Search for a location..."
    >

    let autocomplete;

    const input = document.getElementById('searchInput');
    autocomplete = new google.maps.places.Autocomplete(input, {
    types: ['(cities)', 'geocode'], // Allow both city and address searches
    componentRestrictions: { country: 'do' }
    });

    // Handle place selection
    autocomplete.addListener('place_changed', function() {
    const place = autocomplete.getPlace();

    if (!place.geometry) {
    return;
    }

    Continue reading...

Compartilhe esta Página