【问题标题】:How to get only India city names in Google Autocomplete iOS?如何在 Google Autocomplete iOS 中仅获取印度城市名称?
【发布时间】:2018-12-13 15:31:59
【问题描述】:

我想在 Google 自动完成功能中仅显示来自印度的城市名称。

我的 PAI 是:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=(strSearch)&country=in&language=en&key=MyKeyhare

这里的示例搜索字符串是:Hy (OR) Hyd

当我发送时:Hy。它显示在城市名称下方

Hyderabad, Telangana, India
Hyattsville, MD, USA
Hyōgo Prefecture, Japan
Hyères, France
Hyvinkää, Finland

当我发送:Hyd。它显示在城市名称下方

Hyderabad, Telangana, India
Hyderabad, Pakistan
Hyde Park, Newtownabbey, UK
Hyderguda, Hyderabad, Telangana, India
Hyde Street, San Francisco, CA, USA

它显示来自所有国家/地区的所有匹配名称,不仅来自印度。但我只想要印度城市名称。有没有可能……

让 url = NSURL(string: "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=(strSearch)&country=in&language=en&key=MyKey")

    let task = URLSession.shared.dataTask(with: url! as URL) { (data, response, error) -> Void in


        do {
            if data != nil{
                let dic = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableLeaves) as!  NSDictionary
                //                    print(dic)
                let status = dic["status"] as! String

                if status == "REQUEST_DENIED" {
                } else if status == "ZERO_RESULTS" {
                } else if status == "INVALID_REQUEST" {
                } else {
                    let dictionary = dic["predictions"] as! NSArray
                    //                        print((dictionary[0] as! [String:Any])["description"]!)
                    for index in 0..<dictionary.count {
                        print((dictionary[index] as! [String:Any])["description"]!)
//                            print((dictionary[index] as! [String:Any])["place_id"]!)
                        self.displayItems.append((dictionary[index] as! [String:Any])["description"]! as! String)
                    }
//                        print("*******************************************")


                    }
                }

            }
        } catch {
            print("Error")
        }
    }

    task.resume()

}

【问题讨论】:

    标签: ios swift google-maps cocoa-touch autocomplete


    【解决方案1】:

    您可以将GMSAutocompleteFiltercountry 一起使用

    GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
    filter.type = kGMSPlacesAutocompleteTypeFilterNoFilter;
    filter.country = @"IN";
    

    查看link

    【讨论】:

      【解决方案2】:

      使用 google SDK 时使用 El Captain 答案。如果您通过 API 使用,请使用以下网址:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=search_str&types=geocode&language=en&key=api-key&components=country:IN 。

      有关更多详细信息,您可以使用我的repository。并检查 URL,我正在做的事情。它是 100% 工作的。

      您可以寻求任何进一步的帮助。

      【讨论】:

        猜你喜欢
        • 2014-09-07
        • 1970-01-01
        • 2019-01-27
        • 1970-01-01
        • 1970-01-01
        • 2011-09-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多