[英]How to restrict user to select city only from google API response
I am using google API to show autocomplete cities, but I want user to always select from available or whatever autocomplete options comes when he starts typing, if user types any city name which is not automated by google api then I have to show error.我正在使用谷歌 API 来显示自动完成城市,但我希望用户总是从可用或他开始输入时出现的任何自动完成选项中进行选择,如果用户输入任何不是由谷歌 API 自动完成的城市名称,那么我必须显示错误。 Is there any way to do this?有没有办法做到这一点? Here I am trying so far please try editing and let me know please.到目前为止,我正在尝试,请尝试编辑并让我知道。
[1]: http://jsfiddle.net/uxvMF/34/
This is probably not the simplest way but if you're selecting cities that are next to each other, you can use the bounds option for Autocomplete with strict bounds enabled这可能不是最简单的方法,但如果您要选择彼此相邻的城市,则可以在启用严格边界的情况下使用自动完成的边界选项
https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete
For example:例如:
var options = {
componentRestrictions: {
country: 'nz'
},
bounds: {
east: -1,
west: 1,
north: 1,
south: -1
},
strictBounds: true
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.