angular - How to return autocomplete values only in a specific radius in Google Autocomplete (ngx-autocom-place)?
问题描述
I'm trying to use Google Places in my Angular app to return to the user in an autocomplete input only address result which are in a radius from a location, so from the documenentation i should use parameters as location
radius
and strictbounds
.
To use autocomplete i'm using the following ngx library but the issue is that after setting all the parameters in the options when i'm trying to write a certain address firstly i get only the one that are in the range BUT if i anyway try to write one out of range or even another city that is out of range it will still return that values and i would prevent it.
Here are my autocomplete options
addressOptions = {
types: ['address'],
componentRestrictions: {
country: 'it'
},
location: new google.maps.LatLng( 44.7179422, 10.5465457),
radius: '1000',
strictbounds: true
};
<input
type="text"
class="form-control"
required
placeholder="es. Via D'israeli"
formControlName="indirizzo"
ngxAutocomPlace
[options]="addressOptions"
(selectedPlace)="addressChange($event)"
/>
解决方案
mytyuk, it seems strictBounds
will only be take into account when passing bounds
property (https://developers.google.com/maps/documentation/javascript/places-autocomplete)
strictBounds is a boolean specifying whether the API must return only those places that are strictly within the region defined by the given bounds. The API does not return results outside this region even if they match the user input.
推荐阅读
- kubernetes - GKE - 如果集群的节点少于 4 个,则持久卷无法挂载到
- laravel - Laravel 活动日志仅在更新时记录属性?
- python - django postgresql 累计和
- java - 使用 maven 和 spring-boot 从 classPath 加载文件
- python - Response.css 在使用 Scrapy 库通过 API 获取数据时返回空列表
- javascript - 关于 JavaScript:脚本标签中包含的 js 文本加载后执行前可以修改其内容吗?
- c++ - C++ 中的 `operator auto() = delete` 的目的是什么?
- rust - 将函数参数与结构字段匹配
- sql - 如何在 presto 中基于一张表中的 2 列加入 3 张表?
- exception - 如何处理 CCXT Binance 间歇性网络错误