我想在Google自动填充功能中仅显示来自印度的城市名称 .
这里的示例搜索字符串是: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
它显示所有匹配的名称,不仅来自印度的所有国家 . 但我只想要印度城市的名字 . 可能吗...
let 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()
}
2 回答
您可以使用
GMSAutocompleteFilter
和country
之类的检查这个link
使用谷歌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%的工作 .
您可以提出任何进一步的帮助 .