Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example using UISearchController to show autocompleted results #137

Open
captainbarbosa opened this issue Mar 2, 2018 · 5 comments
Open

Comments

@captainbarbosa
Copy link
Contributor

captainbarbosa commented Mar 2, 2018

An example of how to use MapboxGeocoder.swift's autocomplete functionality with a UISearchController would be particularly useful.

@anoffsinger
Copy link

+1 this would be very helpful.

I'm not an experienced iOS developer and want to use Mapbox for a new Swift project. The lack of documentation around this specific interaction is making me fallback to MapKit rather than Mapbox, which has a fair amount of documentation (both official and unofficial) around this.

@1ec5
Copy link
Contributor

1ec5 commented Jul 13, 2018

Putting this example in mapbox/ios-sdk-examples#17 would give it more visibility (i.e., on this examples site).

@jbarros35
Copy link

Please wherever do it because there is no clear way to do that.
For example I have a search for addresses, I already have the country selected but I need to search streets by name and autocomplete.

@mtcamesao
Copy link

Is this feature still not implemented? I already created an app on the Android side and currently converting it to iOS only to find out a key feature such as this isn't really documented and seems to be pushed aside constantly.

@1ec5
Copy link
Contributor

1ec5 commented Dec 19, 2019

This library already provides much of the functionality needed to implement an autocompleting search UI; this ticket only tracks adding an example of doing so. Compared to Android, it’s more straightforward on iOS to set up a standard search UI, and you’d benefit from all the UI customization hooks that would be available as a result. The steps look something like this:

  1. Add a UISearchController and UITableViewController to your view controller. Set your view controller as the search controller’s search updater.
  2. Call Geocoder.geocode(_:completionHandler:) in response to UISearchResultsUpdating.updateSearchResults(for:). Here’s an example set of options to use:
    let options = ForwardGeocodeOptions(query: text)
    options.locale = .autoupdatingCurrent
    options.allowedScopes = [.address, .pointOfInterest]
    options.maximumResultCount = 10
    options.focalLocation = location
  3. In the completion handler, stash the placemarks in a property of your view controller and reload the table view.
  4. In UITableViewDataSource methods such as tableView(_:cellForRowAt:), configure a UITableViewCell (or a custom subclass) to display details about the placemark.

This Apple example shows how to do it using MapKit, but the types and principles are similar when using MapboxGeocoder.swift. Hope this gives you a decent starting point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants