Giter VIP home page Giter VIP logo

googleplacesrow's Introduction

Platform iOS Swift 2 compatible Swift 2 compatible CocoaPods compatible License: MIT

By Xmartlabs SRL.

Current Google Places version used is 2.2 (in version 2.1.0)

Swift 3 is supported from version 2.0

Contents

Introduction

GooglePlacesRow is a row extension for Eureka. It implements a row where the user can use Google Places autocomplete functionality to select a place suggested by the API.

GooglePlacesRow includes two rows with similar functionality but their options are displayed diferently:

  • GooglePlacesAccessoryRow: displays a collection view as the inputAccessoryView of the cell. The user will be able to scroll horizontally to select the desired place
  • GooglePlacesTableRow: displays a UITableView directly below the cell for the user to choose the desired option.

The project is experimental and open to changes although it is already quite customizable.

Please follow the installation instructions

Usage

// in AppDelegate.swift
import GoogleMaps

// then in application:didFinishLaunchingWithOptions:
let apiKey = "YOUR_API_KEY"
GMSServices.provideAPIKey(apiKey)


//in your subclass of FormViewController
form +++ Section("Choose from table view")
            <<< GooglePlacesTableRow()
     +++ Section("Customized cell, customized layout")
         <<< GooglePlacesAccessoryRow().cellSetup { cell, row in
             (cell.collectionViewLayout  as? UICollectionViewFlowLayout)?.sectionInset = UIEdgeInsetsZero
             (cell.collectionViewLayout  as? UICollectionViewFlowLayout)?.minimumInteritemSpacing = 40
             cell.customizeCollectionViewCell = { cvcell in
                 cvcell.label.textColor = UIColor.redColor()
                 cvcell.layer.borderColor = UIColor.redColor().CGColor
                 cvcell.layer.borderWidth = 1
                 cvcell.layer.cornerRadius = 4
                 }
        }

To see what you can customize have a look at the Customization section or the FAQ

Dependencies

  • Eureka (obviously)
  • GooglePlaces (and all the frameworks it depends on)
  • GoogleMapsBase

Requirements

  • iOS 8.0+
  • Xcode 8.3+

Getting involved

  • If you want to contribute please feel free to submit pull requests.
  • If you have a feature request please open an issue.
  • If you found a bug or need help please check older issues or the FAQ before submitting an issue..

Before contributing check the CONTRIBUTING file for more info.

If you use GooglePlacesRow in your app we would love to hear about it! Drop us a line on twitter.

Examples

For Swift 2 (1.0.1 or before)

Follow these steps to run Example project:

  • Clone GooglePlacesRow repository
  • Run carthage update in the root of the project
  • Open GooglePlacesRow workspace
  • Set your Google places API KEY in AppDelegate.swift
  • and run the Example project.

For Swift 3

Follow these steps to run Example project:

  • Clone GooglePlacesRow repository
  • Execute git submodule add https://github.com/xmartlabs/Eureka.git in the cloned folder.
  • Open GooglePlacesRow workspace
  • Set your Google places API KEY in AppDelegate.swift
  • and run the Example project.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

To install GooglePlacesRow, simply add the following line to your Podfile:

pod 'GooglePlacesRow'

This will also install Eureka and GooglePlaces.

Note: Do not add pod 'GooglePlaces' to your podfile as this library includes it as a vendored framework

Customization

General customization

There are five variables that you can use to modify the default behaviour of these rows:

  • In the row:
    • placeFilter: Is a GMSAutocompleteFilter used in the request to Google Places to define what kind of suggestions will be returned (e.g. cities, addresses, country). Refer to the official docummentation of Google for more detailed information.
    • placeBounds: Bounds to limit the search for places. Refer to the official docummentation of Google for more detailed information.
    • onNetworkingError: Block that is called when the request to Google Places returns an error
  • In the cell:
    • useTimer: If the request to Google Places should be throttled using a timer. If true then it will wait for timerInterval seconds before making a request. If the user continues entering text into the row then the previous request will not be fired
    • timerInterval: The interval in seconds used for the timer explained above

GooglePlacesAccessoryRow

GooglePlacesAccessoryRow uses a generic GooglePlacesCollectionCell cell whose generic parameter is the UICollectionViewCell class used in the inputAccessoryView.

  • If you just want to change minor things of the cell (you most probably will want to) then the customizeCollectionViewCell callback is for you. This block is called in the delegates collectionView:cellForItemAtIndexPath: method.

  • If you want to change the layout of the collectionView then you can use/modify/override the collectionViewLayout attribute in the cellSetup method when declaring the row. Have a look at the examples for this.

  • If you want to change something about the collectionView (e.g. its height, backgroundColor) then you can also do that in the cellSetup method. Have a look at the examples for this.

  • If you want to change the collection view cell of the inputAccessoryView drastically then there is nothing easier than creating your own row (MyGooglePlacesAccessoryRow) with your own MyCollectionViewCell:

public final class MyGooglePlacesAccessoryRow: _GooglePlacesRow<GooglePlacesCollectionCell<MyCollectionViewCell>>, RowType {
    required public init(tag: String?) {
        super.init(tag: tag)
    }
}

In this case just make sure your cell conforms to EurekaGooglePlacesCollectionViewCell

GooglePlacesTableRow

GooglePlacesTableRow uses a generic GooglePlacesTableCell cell whose generic parameter is the UITableViewCell class used to create the cells displayed in a UITableView with the suggested options from Google Places.

  • If you just want to change minor things of the cells that display the options (you will most probably want to) then the customizeTableViewCell callback is for you. This block is called in the delegates tableView:cellForRowAtIndexPath: method.

  • You can customize attributes of the tableView that is displayed with the options. You should do this in cellSetup and keep in mind that the frame of the tableView is reset each time the tableView is displayed.

  • If you want to change these cells drastically then there is nothing easier than creating your own row (MyGooglePlacesAccessoryRow) with your own MyCollectionViewCell:

public final class MyGooglePlacesAccessoryRow: _GooglePlacesRow<GooglePlacesCollectionCell<MyCollectionViewCell>>, RowType {
    required public init(tag: String?) {
        super.init(tag: tag)
    }
}

In this case just make sure your cell conforms to EurekaGooglePlacesTableViewCell

FAQ

Xcode says ld: framework not found GoogleMaps for architecture x86_64.

This is most probably because you forgot to tell Xcode where GoogleMapsBase.framework or GooglePlaces.framework is or you did forget to download it altogether. Please follow the example instructions or the installation instructions.

Future work

  • Carthage compatibility
  • Investigate automation of the installation process

Author

Change Log

This can be found in the CHANGELOG.md file.

googleplacesrow's People

Contributors

mats-claassen avatar ijaureguialzo avatar

Watchers

James Cloos avatar Dhiman Ranjit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.