2016-01-18 64 views
2

我使用的是Google地圖自動完成查詢,就像您在下面看到的一樣,我確定了我的位置周圍的自動完成的邊界,但我仍然得到距離我的位置很遠的地方。我也檢查了邊界,西南邊界,東南邊界,他們也是如此,但是這裏的地方並不是這樣。Google Swift自動完成查詢

var northRegion = CLLocationCoordinate2DMake((locationManager.location?.coordinate.latitude)!*1.0001, (locationManager.location?.coordinate.longitude)!*1.01) 
    var southRegion = CLLocationCoordinate2DMake((locationManager.location?.coordinate.latitude)!*0.99, (locationManager.location?.coordinate.longitude)!*0.9999) 

    var bounds = GMSCoordinateBounds(coordinate: northRegion, coordinate: southRegion) 

    print(locationManager.location?.coordinate.latitude) 
    print(locationManager.location?.coordinate.longitude) 
    print(bounds.northEast) 
    print(bounds.southWest) 
    var filter = GMSAutocompleteFilter() 
    filter.type = GMSPlacesAutocompleteTypeFilter.Geocode 


    var yourLat = locationManager.location?.coordinate.latitude 
    var yourLon = locationManager.location?.coordinate.longitude 



    placesClient = GMSPlacesClient() 

    placesClient?.autocompleteQuery("cape", bounds: bounds, filter: filter, callback: { (result, error) -> Void in 

     for item in result! { 

      print(item.attributedFullText) 
     } 
    }) 

例如,我的位置是伊斯坦布爾,當我寫這個,我得到了開普敦的數據。

回答

1

好的我在GMSPlacesClient中發現這個 * @param bounds用於偏差結果的邊界。這不是一個嚴格的限制 - 地方可能仍然*返回這些範圍之外。該參數可能爲零。

因此,自動完成查詢無法以邊界方式過濾地點。

1

也許有點晚回答,但你可以嘗試使用filter.country = countryCode,我用它來限制結果只是我的國家。