Google Place自动完成API界限无法在swift iOS中运行

时间:2018-04-14 05:26:59

标签: ios swift google-places-api google-places googleplacesautocomplete

我已经实施了google place autocomplete api,我已经应用了界限来限制我的自动完成搜索到一个特定的城市奥兰多,佛罗里达州,美国但谷歌地方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的学位)。我发现我的边界过滤器无法正常工作后,我添加了国家文件管理器美国的另一件事。到目前为止,我能够将地址搜索限制在美国。

1 个答案:

答案 0 :(得分:0)

您还应该在article:nth-child(odd) .thumbnail { float: right; } article:nth-child(even) .thumbnail { float: left; } 来电中定义boundsMode参数。看一下文档:

https://developers.google.com/places/ios-api/reference/interface_g_m_s_places_client

placesClient.autocompleteQuery()必须等于boundsMode
将边界解释为限制。默认情况下,边界被解释为偏差,这是您从外部获取结果的原因。

https://developers.google.com/places/ios-api/reference/group___autocomplete_bounds_mode#gafbfae308afa98048c1e97864baa88568

GMSAutocompleteBoundsMode.Restrict

SDK 2.5中引入了参数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, boundsMode: GMSAutocompleteBoundsMode.Restrict, filter: filter, callback: { (results, error) in })

我希望这有帮助!