Adding a custom cell to Google Places Autocomplete with Swift?
NickName:AkkaVoskuil Ask DateTime:2016-12-01T09:44:26

Adding a custom cell to Google Places Autocomplete with Swift?

I am implementing a Places autocomplete with the Google Places API for iOS. Using Swift. My code for the searchview is the following (connected to an empty ViewController in the storyboard):

import UIKit
import GooglePlaces

protocol PlacesProtocol: class {
    func returnPlaces(place:GMSPlace!)
}

class AutoCompleteViewController: UIViewController {

    var resultsViewController: GMSAutocompleteResultsViewController?
    var searchController: UISearchController?
    var resultView: UITextView?
    var delegate: PlacesProtocol?

    override func viewDidLoad() {
        super.viewDidLoad()

        resultsViewController = GMSAutocompleteResultsViewController()
        resultsViewController?.delegate = self


        searchController = UISearchController(searchResultsController: resultsViewController)
        searchController?.searchResultsUpdater = resultsViewController

        let subView = UIView(frame: CGRectMake(0, 65.0, 375.0, 45.0))

        subView.addSubview((searchController?.searchBar)!)
        self.view.addSubview(subView)
        searchController?.searchBar.sizeToFit()
        searchController?.hidesNavigationBarDuringPresentation = false

        // When UISearchController presents the results view, present it in
        // this view controller, not one further up the chain.
        self.definesPresentationContext = true
    }
}

// Handle the user's selection.
extension AutoCompleteViewController: GMSAutocompleteResultsViewControllerDelegate {
    func resultsController(resultsController: GMSAutocompleteResultsViewController,
                           didAutocompleteWithPlace place: GMSPlace) {
        searchController?.active = false
        // Do something with the selected place.
        delegate!.returnPlaces(place)
        self.navigationController?.popViewControllerAnimated(true)
    }

    func resultsController(resultsController: GMSAutocompleteResultsViewController,
                           didFailAutocompleteWithError error: NSError){
        // TODO: handle the error.
        print("Error: ", error.description)
    }

(Taken from a tutorial)

The autocomplete works fine, but I need to add a static cell to the resultsTable with the option 'My Location'. Is there a way to access this? I am thinking either accessing the resultTable's cellForRowAtIndexPath function and adding an extra cell there, or accessing the array of places and putting in the option in the first position (more hacky), but I cant seem to figure out how and Google isn't giving me any results..

Thank you so much for any help!

Copyright Notice:Content Author:「AkkaVoskuil」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40901287/adding-a-custom-cell-to-google-places-autocomplete-with-swift

More about “Adding a custom cell to Google Places Autocomplete with Swift?” related questions

Adding a custom cell to Google Places Autocomplete with Swift?

I am implementing a Places autocomplete with the Google Places API for iOS. Using Swift. My code for the searchview is the following (connected to an empty ViewController in the storyboard): import

Show Detail

Google Places Autocomplete Swift 3

I want to integrate the Google Places Autocomplete API in my project but I am unable to achieve it with the documentation and also couldn't get some solid references for Swift-3. Can anyone please ...

Show Detail

add custom array to google autocomplete places angularJS

In my application, I am using autocomplete for google places using the directive gm-places-autocomplete. I want this autocomplete suggestion to be enhanced with my custom array which has be listed...

Show Detail

google places autocomplete ios swift integrate with uitextfield

I am trying to implement google places auto complete api in swift 2.0 project by using the following library: https://github.com/watsonbox/ios_google_places_autocomplete the only thing i am not a...

Show Detail

How to add google places autocomplete to xcode with swift (tutorial)

I want to add google places autocomplete to xcode with swift, so users can search on a city and press enter, so should the app show that city on the map. I´m using google maps, so it has to be

Show Detail

Tutorial for Google autocomplete places api for swift

I would like to have an autocomplete textfield that autocompletes locations for me like the one for android: https://developers.google.com/places/training/autocomplete-android Does anyone know wh...

Show Detail

Add Custom Default Places In Google Places AutoComplete

I want to make an input with autocomplete use google places API. And this is my code: var options = { componentRestrictions: { country: "de" } }; var place = ''; var

Show Detail

Google Places Autocomplete

I am using google.maps.places.Autocomplete, I want city to autocomplete but restrict the autocomplete results to multiple cities, not just one as in the google documentation. this is what I have ...

Show Detail

Google places autocomplete - adding custom result as last suggestion

I'm using google places autocomplete to show location suggestions for users. I have added a custom result to the autocomplete suggestions using the following code - $timeout(function(){ ...

Show Detail

Using Google Places Autocomplete with Meteor

So I am trying to add the search bar of https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform to my Meteor app. First I needed to load the Google Places

Show Detail