Minnen
Minnen

Reputation: 441

Google Places API places types issue

I'm using the code detailed below to get an auto complete text field for worldwide airports but it doesn't give any results, however, if i change the type from airport to cities it does work.

The HTML:

<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="author" content="">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
    <script type="text/javascript" src="js/geo.js"></script>
</head>
<body>
    <div class="container">
        <div class="header"></div>
        <div id="nav-bar">
            <!-- <?php include ("nav-bar.php"); ?> -->
        </div>
        <div class="content">
            <div class="left-panel"></div>
            <div class="right-panel">
            <form action="">
                Origin:<br>
                <input type="text" name="" id="searchTextField"><br>
                Destination:<br>
                <input type="text" name=""><br>
                Departure:<br>
                <input type="date" name=""><br>
                Return:<br>
                <input type="date" name=""><br>                 
            </form>
            </div>
        </div>
        <div class="footer"></div>
    </div>
</body>

The JS:

function initialize() 
{
    var input = document.getElementById('searchTextField');
    var options = {
        types: ['(airport)'],
};
    autocomplete = new google.maps.places.Autocomplete(input, options);
}

google.maps.event.addDomListener(window, 'load', initialize);

List of supported types: https://developers.google.com/places/supported_types

Any kind of help is greatly appreciated and as always thanks in advance for taking the time to read this.

Upvotes: 2

Views: 795

Answers (1)

Lal
Lal

Reputation: 14810

There is no airport place type. Read more about it here

types | Array.<string>

The types of predictions to be returned. Four types are supported: 'establishment' for businesses, 'geocode' for addresses, '(regions)' for administrative regions and '(cities)' for localities. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the 'geocode' and 'establishment' types, but note that this will have the same effect as specifying no types.

To get the airports from places api you'll have to use an url that mentions the type as airport. see it here

Upvotes: 2

Related Questions