简体   繁体   English

如何限制用户只能从谷歌 API 响应中选择城市

[英]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.

相关问题 我们如何将谷歌地图自动完成限制为仅特定城市? - How can we restrict google map autocomplete to only a particular city? 将Google自动完成输出限制为仅城市 - Restrict google autocomplete output to city only 将Google Maps Directions API限制为特定城市 - Restrict Google Maps Directions API to specific city 仅允许从 Google 地图 API 自动完成(城市)中选择的值 - Allow only selected value from Google maps API autocomplete (city) 如何基于Google API使仅城市自动完成输入 - How to make city only autocomplete input based on google api 如何限制 Google 为某些城市名​​称和所有州名称设置 api 自动完成功能? - How to restrict Google places api autocomplete for some city names and all state names? 如何限制Google Map API在特定国家和城市内查找地点? - how to restrict google map api to find places within a specific country and city both? 如何在仅具有城市名称的Google Maps API上获取城市的Lat,Alt - How to get a city's Lat,Alt on google maps API having only the name of the city 如何从谷歌地图API获取城市和邮政编码? - How to get city and postal code from google maps API? 如何始终从谷歌地理编码 api 获取城市 - How to always get city from google geocoding api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM