├── .gitignore ├── README.md ├── dist ├── gplaces.css ├── gplaces.js └── gplaces.min.js ├── gulpfile.js ├── index.js ├── less ├── app.less └── components │ └── gplaces.less ├── lib ├── .DS_Store ├── base-tmpl.js ├── base-view.js ├── error-tmpl.js ├── errors.js ├── http.js ├── input-model.js ├── noop.js ├── prediction-tmpl.js ├── register-browser-content.js ├── selection-position-model.js ├── server.js └── utils.js ├── package.json ├── standalone-build.js └── test ├── config.js ├── public ├── index.html └── js │ └── app.js └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test/config.local.js 3 | test/public/dist/* 4 | .DS_Store 5 | npm-debug.log 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gplaces 2 | 3 | > Dependency-free, google maps auto completion input. [See Demos](http://gplaces.goodybag.com) 4 | 5 |  6 | 7 | __install__ 8 | 9 | ``` 10 | npm install -S gplaces 11 | or 12 | bower install gplaces 13 | ``` 14 | 15 | __usage__ 16 | 17 | After importing the script, setting up your proxy, and setting `gplaces.http`, you can simply add the attribute `data-gplaces` to an HTML element that accepts input and can respond to `keyup` events: 18 | 19 | ```html 20 | 21 | 22 | 23 | ``` 24 | 25 | Also, see [browser support](#browser-support). 26 | 27 | ## Detailed Usage guide 28 | 29 | There are two main hurdles to getting this to work: 30 | 31 | 1. Setting up your own proxy to Google's API (see [why do I need a proxy?](#why-do-i-need-a-proxy)) 32 | 2. Overriding gplaces http implementation to make a request to your api 33 | 34 | 35 | __Get Google API Access__ 36 | 37 | Setup a project in the Google Developers Console: https://code.google.com/apis/console 38 | 39 | After creating your project, find the Google Places API Web Service and enable it. Under the credentials section on the left, get an API key. 40 | 41 | __Setup your proxy__ 42 | 43 | Since Google's Autocomplete API isn't very CORS-friendly, you'll need to setup a proxy on your own proxy. This is easy to do with node and express: 44 | 45 | ``` 46 | npm install -S gplaces 47 | ``` 48 | 49 | In your express app, 50 | 51 | ```javascript 52 | var express = require('express'); 53 | var app = express(); 54 | 55 | app.use( require('body-parser')() ); 56 | 57 | // Mount your api endpoint wherever you like 58 | app.get( '/api/places-autocomplete' 59 | , require('gplaces').proxy({ 60 | key: 'my-api-key' 61 | }) 62 | ); 63 | 64 | app.listen( 3000, function( error ){ 65 | /* ... */ 66 | }); 67 | ``` 68 | 69 | If you need help setting up a proxy for other platforms, create an issue and we'll help you out. 70 | 71 | __Implement `gplaces.http`:__ 72 | 73 | A _feature_ of the gplaces library is the fact that the library will piggy-back off of your app's existing http interface to cut down on library size and errors. 74 | 75 | Before making any requests, setup gplaces http method. Here's an example using [superagent](https://github.com/visionmedia/superagent) and [browserify](https://github.com/substack/browserify): 76 | 77 | ``` 78 | npm install -S superagent 79 | ``` 80 | 81 | ```javascript 82 | var request = require('superagent'); 83 | var gplaces = require('gplaces'); 84 | 85 | gplaces.http( function( input, callback ){ 86 | request 87 | .get('/api/places') 88 | .query({ input: input }) 89 | .end( callback ); 90 | }); 91 | ``` 92 | 93 | Here's an example using jquery: 94 | 95 | ```javascript 96 | gplaces.http( function( input, callback ){ 97 | $.getJSON( '/api/places?input=' + input ) 98 | .error( callback ) 99 | .success( callback.bind( null, null ) ); 100 | }); 101 | ``` 102 | 103 | ## API 104 | 105 | You can either use the HTML attribute api or the JavaScript API. 106 | 107 | ### HTML Attribute API 108 | 109 | Adding the `data-gplaces` attribute any html element that has a value and can respond to keyup events will automatically register the gplaces plugin. 110 | 111 | ```html 112 | 113 | ``` 114 | 115 | #### `data-target="[selector]"` 116 | 117 | Optional CSS selector that the autocomplete results will be rendered to: 118 | 119 | ```html 120 | 121 | ... 122 |