如何定位偏见谷歌地方自动填充?

时间:2017-05-16 23:34:35

标签: ios swift google-maps autocomplete

Google正在使用此Tutorial将Google地方信息自动填充功能实施到使用Swift的iOS应用中,但我尝试将结果限制在特定位置,因为link表示这是可能的,但对于我的生活,我看不到任何地方这样做..........

这是视图控制器:

flask_restful.marshal_with

2 个答案:

答案 0 :(得分:0)

在文档中它说明了用于此的类。

  

GMSCoordinateBounds对象将结果偏向由纬度和经度范围指定的特定区域。

注意:如果人们搜索埃菲尔铁塔,他们仍然可以看到它,你无法完全删除这些界限之外的所有内容。但99%的结果可能都在这些范围内。这只是一种偏见搜索。

给GMSCoordinateBounds类角经度和纬度,以及它。

它的使用方式如下:

let northEastBoundsCorner = CLLocationCoordinate2D(latitude: -33.843366,
                                            longitude: 151.134002)
let southWestBoundsCorner = CLLocationCoordinate2D(latitude: -33.875725,
                                            longitude: 151.200349)
let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,
                                 coordinate: swBoundsCorner) 
func placeAutocomplete() {
     let filter = GMSAutocompleteFilter()
     filter.type = .establishment
     placesClient.autocompleteQuery("Sydney Oper", bounds: bounds, filter: filter, callback: {(results, error) -> Void in
     if let error = error {
        print("Autocomplete error \(error)")
        return
     }
     if let results = results {
        for result in results {
            print("Result \(result.attributedFullText) with placeID \(result.placeID)")
        }
     }
}) }

以下是他们使用文档的网址: Set the GMSCoordinateBounds of autocomplete

答案 1 :(得分:0)

只是为了澄清NebojsaNadj对OP的回答 - 您可以先使用点设置偏差的边界来表示边界框。因此,将自动完成偏向于奥巴哈,内巴斯卡,例如:

let northEastBoundsCorner = //Omaha's NE corner in CLCoordinate2D
let southWestBoundsCorner = //Omaha's SW corner in CLCoordinate2D
let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,
                             coordinate: swBoundsCorner)

因此,当您实例化GMSController时,您只需将其设置为上述边界myGMSAutoCompleteController.autocompleteBounds = bounds的自动完成边界。在引用的demo中,它将是这样的:

import UIKit
import GooglePlaces

class ViewController: UIViewController {

 // Present the Autocomplete view controller when the button is pressed.
 @IBAction func autocompleteClicked(_ sender: UIButton) {
    let autocompleteController = GMSAutocompleteViewController()
//Here's where you add it
    let northEastBoundsCorner = //Omaha's NE corner in CLCoordinate2D
    let southWestBoundsCorner = //Omaha's SW corner in CLCoordinate2D
    let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,
                             coordinate: swBoundsCorner)
    controller.autocompleteBounds = bounds
//back to demo code
    autocompleteController.delegate = self
    present(autocompleteController, animated: true, completion: nil)
  }
}
//see the demo for the rest of the code