在用户开始输入位置名称的文本字段中,我想在下面显示名称列表作为用户类型,类似于搜索字段,如字母“A”开头显示“A”的所有选项。如何实现这一目标。
如何获取位置名称?
请指导以上内容。如果还有其他事情要问,请随时提出。
提前致谢。
答案 0 :(得分:1)
您确实需要使用google api ..这是一个链接:https://developers.google.com/places/documentation/autocomplete
The Google Places Autocomplete API is a web service that returns Place information based on text search terms, and, optionally, geographic bounds. The API can be used to provide autocomplete functionality for text-based geographic searches, by returning Places such as businesses, addresses, and points of interest as a user types.
您需要使用https://code.google.com/apis/console/#project:18836829369创建API密钥。当您得到答案时,您只需要在json响应中查看predictions
。
希望这会有所帮助:)
答案 1 :(得分:0)
您应该使用google place API。我对此并不了解,但this链接会有所帮助。
请记住,这不是自动填充搜索栏的位置搜索。
答案 2 :(得分:0)
您可以使用以下给定的功能:
- (void)searchText:(NSString *)substring
{
for (int i = 0; i < [yourArray count]; i++)
{
NSString *curString = [[yourArray objectAtIndex:i]lowercaseString];
NSString *searchString = [substring lowercaseString];
if ([curString rangeOfString:curStringSmall].location == NSNotFound)
{
}
else
{
//This means searched text is found in your array. you can store it in new array. Which will give you only the search criteria matched element.
}
}
}
您需要从textFieldShouldBeginEditing
:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self searchText:txtSearch.text];
return YES;
}