谷歌地图/地方的Javascript API自动完成类型限制 [英] Google Maps/Places Javascript API Autocompletion Restrict Types

查看:336
本文介绍了谷歌地图/地方的Javascript API自动完成类型限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌地图/地方的JavaScript API的输入框的位置自动完成。我试图限制类型正在由自动完成返回地方。我很新的CoffeeScript(和一般的编码),但因为我在这里有code段,我想看看是否有人可以看到在这个code任何可能会造成调用谷歌不考虑到地方类型过滤器。请注意,餐厅只是作为测试(不成功的)。

我已经通过这里上其他几个问题,其中包括阅读:
<一href=\"http://stackoverflow.com/questions/10637183/how-can-i-restrict-the-google-maps-places-librarys-autocomplete-to-suggestions\">How我可以限制谷歌地图的地方图书馆的自动填充的只有一个城市的地方建议?
<一href=\"http://stackoverflow.com/questions/8282026/how-to-limit-google-autocomplete-results-to-city-and-country-only\">How限制谷歌的自动完成结果为城市和国家唯一

不幸的是,它看起来像我使用的语法是正确的,这就是为什么我问这个问题,因为无论是哪个式的我用自动完成的结果不会改变。

感谢您的帮助。

 #自动完成回调
autocomplete_options = {
  类型:['餐厅']#地理code,建立(地区),(市)
}
自动完成=新google.maps.places.Autocomplete(的document.getElementById'locationSearchField',autocomplete_options)
google.maps.event.addListener自动完成,place_changed', - &GT;
  地方= autocomplete.getPlace()


解决方案

此结构:

  F(摹X,Y)

是间preTED是这样的:

  F(克(X,Y))

这意味着 autocomplete_options 这里:

 自动完成=新google.maps.places.Autocomplete(的document.getElementById'locationSearchField',autocomplete_options)

被视为一个参数的document.getElementById google.maps.places.Autocomplete 永远看不到它。如果您添加括号:

 自动完成=新google.maps.places.Autocomplete(的document.getElementById('locationSearchField'),autocomplete_options)
// ------------------------------------------------ ----------------------- ^ ^ ---------------------

然后每个人都应该得到你期待他们的论点。

I'm using the Google Maps/Places javascript API for autocompletion of locations in an input box. I'm trying to restrict the types of places that are being returned by the autocompletion. I'm very new to coffeescript (and coding in general), but since I have the code snippet here I wanted to see if anyone can see anything in this code that might be causing the call to Google to not consider the place "types" filter. Note that "restaurants" was just used as a test (an unsuccessful one).

I've read through several other questions on here, amongst them: 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

Unfortunately, it looks like the syntax I'm using is correct, which is why I'm asking this question because no matter which "type" I use the autocompletion results do not change.

Thanks for any help.

# 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()

解决方案

This structure:

f(g x, y)

is interpreted like this:

f(g(x, y))

That means that autocomplete_options in here:

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

is seen as an argument to document.getElementById and google.maps.places.Autocomplete never sees it. If you add parentheses:

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

then everyone should get the arguments that you're expecting them to.

这篇关于谷歌地图/地方的Javascript API自动完成类型限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆