【问题标题】:Google Maps/Places Javascript API Autocompletion Restrict TypesGoogle Maps/Places Javascript API 自动完成限制类型
【发布时间】:2013-10-11 18:31:07
【问题描述】:

我正在使用 Google Maps/Places javascript API 来自动完成输入框中的位置。我正在尝试限制自动完成返回的地点类型。我对coffeescript(以及一般的编码)非常陌生,但是由于我在这里有代码sn-p,我想看看是否有人可以在此代码中看到任何可能导致对Google的调用不考虑该位置的内容“类型”过滤器。请注意,“restaurants”只是用作测试(不成功的测试)。

我已经阅读了这里的其他几个问题,其中包括: How can I restrict the Google Maps Places Library's Autocomplete to suggestions of only one city's places? How to limit google autocomplete results to City and Country only

不幸的是,看起来我使用的语法是正确的,这就是我问这个问题的原因,因为无论我使用哪种“类型”,自动完成结果都不会改变。

感谢您的帮助。

# autocomplete callback
autocomplete_options = {
  types: ['restaurants'] # geocode, establishment, (regions), (cities)
}
autocomplete = new google.maps.places.Autocomplete(document.getElementById 'locationSearchField', autocomplete_options)
google.maps.event.addListener autocomplete, 'place_changed', ->
  place = autocomplete.getPlace()

【问题讨论】:

    标签: google-maps-api-3 autocomplete coffeescript google-places-api


    【解决方案1】:

    这个结构:

    f(g x, y)
    

    是这样解释的:

    f(g(x, y))
    

    这意味着autocomplete_options在这里:

    autocomplete = new google.maps.places.Autocomplete(document.getElementById 'locationSearchField', autocomplete_options)
    

    被视为document.getElementById 的参数,而google.maps.places.Autocomplete 从未看到它。如果加括号:

    autocomplete = new google.maps.places.Autocomplete(document.getElementById('locationSearchField'), autocomplete_options)
    // -----------------------------------------------------------------------^---------------------^
    

    那么每个人都应该得到你期望他们得到的论点。

    【讨论】:

    • 它告诉我不要在 cmets 中说“谢谢”,mu,但谢谢!效果很好,您的解释,尤其是对于所有这一切的新手,必须受到赞赏和易于理解。
    猜你喜欢
    • 1970-01-01
    • 2012-06-10
    • 2015-11-09
    • 2013-10-10
    • 1970-01-01
    • 2015-02-02
    • 2020-05-11
    • 2015-06-05
    • 2012-03-15
    相关资源
    最近更新 更多