最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get only city names with Google Maps API autocompletion - Stack Overflow

programmeradmin1浏览0评论

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

var autoplete = new google.maps.places.Autoplete(document.getElementById('adr'));
City : <input id="adr" type="text" class="form-control" value="" >
<script src=";amp;libraries=places" type="text/javascript"></script>

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

var autoplete = new google.maps.places.Autoplete(document.getElementById('adr'));
City : <input id="adr" type="text" class="form-control" value="" >
<script src="http://maps.googleapis./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 autopletion but for city names only? i.e. no street names, no country names, no region names ?

Share Improve this question asked Jan 27, 2015 at 12:26 BasjBasj 46.4k110 gold badges452 silver badges803 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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

var autoplete = new google.maps.places.Autoplete(yourHTMLElement, { types: ['(cities)']});

var autoplete = new google.maps.places.Autoplete(
  document.getElementById('adr'),
  { 
    types: ['(cities)']
  }
);
City : <input id="adr" type="text" class="form-control" value="" style="width:100%">
<script src="http://maps.googleapis./maps/api/js?sensor=true&amp;libraries=places" type="text/javascript"></script>

发布评论

评论列表(0)

  1. 暂无评论