我已经实现了 google place 自动完成 api,并且我已经应用了界限来将我的自动完成搜索限制在美国佛罗里达州奥兰多市的一个特定城市,但是 Google place api 并没有只过滤这个城市的数据。它正在搜索遍布美国和美国以外的其他城市名称。我希望谷歌自动完成 api 只返回这个城市地址。这是相同的代码:
let placesClient = GMSPlacesClient()
let searchBound = getCoordinateBounds(latitude: CLLocationDegrees(28.5383), longitude: CLLocationDegrees(81.3792), distance: 1.45)
let filter = GMSAutocompleteFilter()
filter.country = "USA"
placesClient.autocompleteQuery(text!, bounds: searchBound, filter: filter, callback: { (results, error) in
})
//我的getCoordinateBounds方法
func getCoordinateBounds(latitude:CLLocationDegrees ,
longitude:CLLocationDegrees,
distance:Double = 0.001)->GMSCoordinateBounds{
let center = CLLocationCoordinate2D(latitude: latitude,
longitude: longitude)
let northEast = CLLocationCoordinate2D(latitude: center.latitude + distance, longitude: center.longitude + distance)
let southWest = CLLocationCoordinate2D(latitude: center.latitude - distance, longitude: center.longitude - distance)
return GMSCoordinateBounds(coordinate: northEast,
coordinate: southWest)
}
注意:我想过滤这个纬度和经度半径约 100 英里的地址(这就是我将度数设为 1.45 的原因)。在我发现我的边界过滤器无法正常工作后,我添加了国家文件管理器美国的另一件事。到目前为止,我能够将地址搜索限制在美国。