Get only city names with Google Maps API autocompletion

10,268

That's in the doc : https://developers.google.com/places/documentation/autocomplete#place_types

var autocomplete = new google.maps.places.Autocomplete(yourHTMLElement, { types: ['(cities)']});
Share:
10,268
Basj
Author by

Basj

I work on R&D involving Python, maths, machine learning, deep learning, data science, product design, and MacGyver solutions to complex problems. I love prototyping, building proofs-of-concept. For consulting/freelancing inquiries : [email protected]

Updated on June 05, 2022

Comments

  • Basj
    Basj almost 2 years

    I use this code to provide autocompletion of location names thanks to the Google Maps API:

    var autocomplete = new google.maps.places.Autocomplete(document.getElementById('adr'));
    City : <input id="adr" type="text" class="form-control" value="" >
    <script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>

    All locations names are provided, like city names "Paris", but also country names "Germany", region names, etc.

    How is it possible to have autocompletion but for city names only? i.e. no street names, no country names, no region names ?