我正在尝试构建一个自动填充文本字段,只需要显示城市/城镇名称.
所以我想做的是当有人进入时
Am
它会显示出来
阿姆斯特丹
阿姆斯特尔芬
所以它只会显示实际的城市名称,除此之外什么都没有.它不需要考虑社区等.
我已经应用了一个过滤器,但这并没有解决它.
lazy var searchCompleter: MKLocalSearchCompleter = {
let sC = MKLocalSearchCompleter()
sC.delegate = self
sC.filterType = .locationsOnly
return sC
}()
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
self.searchSource = completer.results.map { $0.title }
DispatchQueue.main.async {
for result in self.searchSource! {
print(result)
}
}
}
func completer(_ completer: MKLocalSearchCompleter, didFailWithError error: Error) {
print(error.localizedDescription)
}
Run Code Online (Sandbox Code Playgroud)
有谁知道是否有可能实现我想要的?
我希望能够MKLocationSearchCompletion
array
在用户搜索搜索栏时找到个人位置.但是,我无法理解项目如何存储到对象中以及是否可以将地标对象(或位置信息)添加到MKLocationSearch
对象中.我从文档中获得的是MKLocalSearchCompleter
对象存储当用户在搜索栏中键入部分字符串时访问的字符串.但我不知道在哪里可以访问此阵列并添加新位置.
以下是代码的结构,以显示搜索完成结果:
var searchCompleter = MKLocalSearchCompleter()
var searchResults = [MKLocalSearchCompletion]()
@IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad() {
searchCompleter.delegate = self
searchBar.delegate = self
}
extension ViewController: MKLocalSearchCompleterDelegate {
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
searchResults = completer.results
searchResultsTableView.reloadData()
}
func completer(_ completer: MKLocalSearchCompleter, didFailWithError error: Error) {
// handle error
}
}
extension ViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: …
Run Code Online (Sandbox Code Playgroud) 是否可以在不提供naturalLanguageQuery的情况下使用MKLocalSearchRequest显示附近的地方?
我知道典型的路线是使用foursquare或google.我用过这两个.
我想实现UISearchController,使用本教程一步一步:
使用MKLocalSearchRequest搜索地点并使用UISearchController显示结果
在本节中......
...我在步骤3中遇到问题.设置表视图数据源
extension LocationSearchTable {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return matchingItems.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
let selectedItem = matchingItems[indexPath.row].placemark
cell.textLabel?.text = selectedItem.name
cell.detailTextLabel?.text = ""
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试override
从cellForRowAtindexPath
tableView函数中删除,在这种情况下我在Xcode中没有错误,但执行后出错:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView (<UITableView: 0x7ff8e03a3800; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H;
gestureRecognizers = <NSArray: …
Run Code Online (Sandbox Code Playgroud) 对于我正在构建的应用程序,我想实现一个功能,允许用户指定葡萄酒的地理原产地(国家(例如法国)、地区(例如波尔多)、次地区(例如保拉克))。
我想确保我不必自己添加所有可用的国家/地区,并且进入数据库的所有信息都是有效的。因此,我决定这样做:
Country
包含所有相关信息的对象。只有当存在这样的物体时,酒车才能被拯救这工作得很好,除了一件事:苹果地图可以从任何地方返回任何东西,比如餐馆、商店等。
我的问题:我如何指定我要寻找的内容?我只能指定我正在搜索的区域,这与我的情况无关。我希望能够告诉苹果地图仅查找国家、地区、城市等。这在某种程度上可能吗?我已经用尽谷歌来解决这个问题,到目前为止还没有找到办法。
当我使用相同的字符串在MKLocalSearch和Apple Maps中搜索时,我会得到不同的结果,通常在Apple Maps中我会得到很多不同的位置,但在MKLocalSearch中我只得到一个.
Apple地图:
我的应用程序使用MKLocalSearch:
在这两种情况下,我都在寻找柏林和MKLocalSearchRequest,我设置了柏林地区的.region属性
Apple使用哪些服务进行位置搜索?
Apple在iOS 9.3中引入了MKLocalSearchCompleter和MKLocalSearchCompletion.我正在努力实现它.它变为两步过程1)输入部分术语 - >生成完整的搜索文本.2)用户选择其中一个来搜索实际位置.
问题是,如果我搜索200个townsend,它会给我一个位置列表,但它会被应用程序视为建议.我们如何识别它是MKMampItem还是建议?
我在 mkmapview 的某个区域内实现了一个 MKLocalSearch,它返回该区域内的一系列餐馆。通过研究,只展示了 10 家餐厅。有没有办法让 MKLocalSearch 可以返回一个区域内的 10 多家餐厅?这是代码,
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc]init];
request.naturalLanguageQuery = @"restaurant";
request.region = midRegion;
MKLocalSearch *localSearch = [[MKLocalSearch alloc]initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
NSMutableArray *annotations = [NSMutableArray array];
[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop){
CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithPlacemark:item.placemark];
annotation.title = item.name;
annotation.subtitle = item.placemark.addressDictionary[(NSString *)kABPersonAddressStreetKey];
annotation.phone = item.phoneNumber;
[annotations addObject:annotation];
}];
[self.mapView addAnnotations:annotations];
}];
}
Run Code Online (Sandbox Code Playgroud) objective-c mkmapview ios mklocalsearch mklocalsearchrequest