Search UI

The SDK comes with a search UI that allows users to type a place name, or pick from a list of categories.

First, make sure your view controller is marked as a TGSearchViewControllerDelegate .

Then, write a method to create and present the TGSearchViewController :

var searchNavController: UINavigationController?

func showSearch() {
    let searchVC = TGSearchViewController.create()
    searchVC.delegate = self

    let navController = searchVC.embedInNavigationController()
    present(navController, animated: true)

    searchNavController = navController
}
// Put this inside your @interface
@property (nonatomic, nullable) UINavigationController *searchNavController;

// Put this inside your @implementation
- (void)showSearch {
    TGSearchViewController *searchVC = [TGSearchViewController create];
    searchVC.delegate = self;

    UINavigationController *navController = [searchVC embedInNavigationController];
    [self presentViewController:navController animated:YES completion:nil];

    self.searchNavController = navController;
}

You will also need to implement these delegate methods:

let exampleCoordinate = CLLocationCoordinate2D(latitude: 34.101558, longitude: -118.340944) // Grauman's Chinese Theatre
let exampleSearchExtent = TGSearchExtent(southwestCoordinate: CLLocationCoordinate2D(latitude: 34.055534, longitude: -118.37313),
                                         northeastCoordinate: CLLocationCoordinate2D(latitude: 34.1504, longitude: -118.308757))

func coordinate(for requestType: TGSearchViewControllerRequestType) -> CLLocationCoordinate2D {
    return exampleCoordinate

    // Note: If you have a TGMapView or MGLMapView, you can get the current location like this:
    //return mapView.centerCoordinate
}

func searchExtent(for requestType: TGSearchViewControllerRequestType) -> TGSearchExtent {
    return exampleSearchExtent

    // Note: If you have a TGMapView or MGLMapView, you can get the current bounds like this:
    //return TGSearchExtent(coordinateBounds: mapView.visibleCoordinateBounds)
}

func didSelect(_ searchResult: TGSearchResult) {
    searchNavController?.dismiss(animated: true)

    // Do something with the selected search result
}
- (CLLocationCoordinate2D)exampleCoordinate {
    return CLLocationCoordinate2DMake(34.101558, -118.340944); // Grauman's Chinese Theatre
}

- (TGSearchExtent *)exampleSearchExtent {
    return [TGSearchExtent.alloc initWithSouthwestCoordinate:CLLocationCoordinate2DMake(34.055534, -118.37313)
                                         northeastCoordinate:CLLocationCoordinate2DMake(34.1504, -118.308757)];
}

- (CLLocationCoordinate2D)coordinateForRequestType:(TGSearchViewControllerRequestType)requestType {
    return self.exampleCoordinate;

    // Note: If you have a TGMapView or MGLMapView, you can get the current location like this:
    //return self.mapView.centerCoordinate;
}

- (TGSearchExtent *)searchExtentForRequestType:(TGSearchViewControllerRequestType)requestType {
    return self.exampleSearchExtent;

    // Note: If you have a TGMapView or MGLMapView, you can get the current bounds like this:
    //return [TGSearchExtent.alloc initWithCoordinateBounds:self.mapView.visibleCoordinateBounds];
}

- (void)didSelectSearchResult:(TGSearchResult *)searchResult {
    [self.searchNavController dismissViewControllerAnimated:YES completion:nil];

    // Do something with the selected search result
}

Add your own logic in that last method to do something with the search result that the user has selected.

Expected Output
TallyGo
Check out the iOS Reference App to see this example in action.

Look for example 205 in the app.