簡體   English   中英

如何在谷歌地圖 ios sdk 中過濾自動完成國家?

[英]How to filter autocomplete country in Google maps ios sdk?

目前,它在每個國家查詢,但我希望它只在新加坡查詢

我找到了一個 stackoverflow 解決方案How to get country specific result with Google autocomplete place api ios sdk? ,但不知道我把代碼放在哪里。

這是代碼,我使用全屏解決方案進行自動完成。

import UIKit
import GoogleMaps

class OnlyLocationViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
                // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func clickMe(sender: UIButton) {
        let autocompletecontroller = GMSAutocompleteViewController()
        autocompletecontroller.delegate = self
        self.presentViewController(autocompletecontroller, animated: true, completion: nil)


    }

}

extension OnlyLocationViewController: GMSAutocompleteViewControllerDelegate{

    func viewController(viewController: GMSAutocompleteViewController, didAutocompleteWithPlace place: GMSPlace) {
        print("Place name: ", place.name)
        print("Place address: ", place.formattedAddress)
        print("Place attributions: ", place.attributions)

        self.dismissViewControllerAnimated(true, completion: nil)
    }


    func viewController(viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: NSError) {
        // To handle error
        print(error)

    }
    func wasCancelled(viewController: GMSAutocompleteViewController) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    func didRequestAutocompletePredictions(viewController: GMSAutocompleteViewController) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = true
    }

    func didUpdateAutocompletePredictions(viewController: GMSAutocompleteViewController) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
    }


}

我應該把過濾器代碼放在哪里?

嘗試使用這個

@IBAction func clickMe(sender: UIButton) {
        let autocompletecontroller = GMSAutocompleteViewController()
        autocompletecontroller.delegate = self
        let filter = GMSAutocompleteFilter()
        filter.type = .Establishment  //suitable filter type
        filter.country = "SG"  //appropriate country code
        autocompletecontroller.autocompleteFilter = filter
        self.presentViewController(autocompletecontroller, animated: true, completion: nil)
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM