谷歌自动完成只能通过邮编和城市进行搜索吗?

时间:2016-05-23 23:55:36

标签: google-maps autocomplete

Google自动完成只能通过zip和city进行搜索吗?我使用了以下代码,但它只会按城市名称搜索。

var options = {
  types: ['cities'],
  componentRestrictions: {country:'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);

2 个答案:

答案 0 :(得分:1)

只需将类型属性设置为区域

var input = document.getElementById("test");
var options = {
  types: ['(regions)'],
  componentRestrictions: {country:'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
#test{
  width: 400px;
}
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA_QD2_rlwEFGhCK0oj2n6cixsvX0D3zgk&libraries=places"></script>

<input type="text" id="test"></input>

答案 1 :(得分:0)

我认为这是不可能的。但是,您可以使用Geocoding API,将zip作为地址参数传递。

您需要对邮政编码进行地理编码。 这是一个示例请求:

Traceback (most recent call last):
File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\llvmlite\binding\ffi.py", line 40, in <module>
    lib = ctypes.CDLL(os.path.join(_lib_dir, _lib_name))
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\datashader\__init__.py", line 5, in <module>
    from .core import Canvas
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\datashader\core.py", line 8, in <module>
    from .utils import Dispatcher, ngjit
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\datashader\utils.py", line 5, in <module>
    import numba as nb
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\numba\__init__.py", line 9, in <module>
    from . import runtests, decorators
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\numba\decorators.py", line 8, in <module>
    from . import config, sigutils
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\numba\config.py", line 10, in <module>
    import llvmlite.binding as ll
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\llvmlite\binding\__init__.py", line 6, in <module>
    from .dylib import *
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\llvmlite\binding\dylib.py", line 4, in <module>
    from . import ffi
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\llvmlite\binding\ffi.py", line 45, in <module>
    lib = ctypes.CDLL(_lib_name)
  File "D:\Adarsh\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found