如何在 Google 自动完成 iOS 中仅获取印度城市名称?
How to get only India city names in Google Autocomplete iOS?
我只想在 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()
}
您可以将 GMSAutocompleteFilter
与 country
一起使用,例如
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.type = kGMSPlacesAutocompleteTypeFilterNoFilter;
filter.country = @"IN";
勾选这个link
当您使用google SDK 时使用El Captain 答案。如果您使用 API,则使用此 url: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% 的工作。
您可以寻求任何进一步的帮助。
我只想在 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()
}
您可以将 GMSAutocompleteFilter
与 country
一起使用,例如
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.type = kGMSPlacesAutocompleteTypeFilterNoFilter;
filter.country = @"IN";
勾选这个link
当您使用google SDK 时使用El Captain 答案。如果您使用 API,则使用此 url: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% 的工作。
您可以寻求任何进一步的帮助。