|
1 | 1 | <link rel="import" href="../polymer/polymer.html">
|
2 | 2 | <link rel="import" href="../paper-input/paper-input.html" />
|
3 |
| -<link rel="import" href="../google-apis/google-maps-api.html" /> |
| 3 | +<link rel="import" href="../iron-jsonp-library/iron-jsonp-library.html"> |
4 | 4 | <link rel="import" href="../iron-icon/iron-icon.html" />
|
5 | 5 | <link rel="import" href="paper-input-place-icons.html" />
|
6 | 6 |
|
7 | 7 | <!--
|
8 | 8 | `paper-input-place`
|
9 |
| -Google Places Autocomplete attached to paper-input |
| 9 | +
|
| 10 | +Google Places Autocomplete attached to paper-input. |
| 11 | +
|
| 12 | +This release is a Polymer 2.0 hybrid element so it will work in 1.x or 2.0 Polymer applications. |
| 13 | +
|
| 14 | + Basic use: |
| 15 | +
|
| 16 | +```html |
| 17 | +<paper-input-place api-key="your google api key" value="{{tourstop.place}}" |
| 18 | + label="Pick a place" hide-error></paper-input-place> |
| 19 | +``` |
| 20 | +The `value` property is an object: |
| 21 | +
|
| 22 | +```js |
| 23 | +{ |
| 24 | + "search": "Guggenheim Museum, 5th Avenue, New York, NY, United States", |
| 25 | + "place_id": "ChIJmZ5emqJYwokRuDz79o0coAQ", |
| 26 | + "latLng": { |
| 27 | + "lat": 40.7829796, |
| 28 | + "lng": -73.95897059999999 |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | +Basic use with validation: |
| 33 | +
|
| 34 | +```html |
| 35 | +<paper-input-place label="Pick a place" api-key="your google api key" value="{{tourstop.place}}"></paper-input-place> |
| 36 | +``` |
| 37 | +
|
| 38 | +
|
10 | 39 |
|
11 | 40 | @demo demo/index.html
|
12 | 41 |
|
13 |
| -@version 1.1.0 |
| 42 | +@version 1.9.0 |
14 | 43 | -->
|
15 | 44 |
|
16 | 45 | <dom-module id="paper-input-place">
|
|
21 | 50 | }
|
22 | 51 | </style>
|
23 | 52 | <template is="dom-if" if="[[apiKey]]" restamp="true">
|
24 |
| - <google-maps-api api-key="[[apiKey]]" on-api-load="_mapsApiLoaded"></google-maps-api> |
| 53 | + <!-- |
| 54 | + NOTE: the GoogleWebComponents collection has not been updated |
| 55 | + to support Polymer 2.0 as of 5/31/2017. There is no estimated |
| 56 | + date at this time. |
| 57 | +
|
| 58 | + For that reason this control is using iron-jsonp-library to load |
| 59 | + the google maps api instead of <google-maps-api>. The url string |
| 60 | + is the same as what would have been issued by the <google-maps-api> so |
| 61 | + even if that control is used elsewhere in your 1.x app, the api will |
| 62 | + not be loaded twice. |
| 63 | + --> |
| 64 | + <iron-jsonp-library |
| 65 | + library-url="[[_gmapApiUrl]]" |
| 66 | + notify-event="map-api-load" |
| 67 | + library-loaded="{{_ijplLoaded}}" |
| 68 | + on-map-api-load="_mapsApiLoaded"></iron-jsonp-library> |
25 | 69 | </template>
|
26 | 70 | <paper-input id="locationsearch" label="[[label]]" value="{{_value}}" invalid="[[invalid]]" disabled$="[[disabled]]" error-message="Invalid - please select a place">
|
27 | 71 | <iron-icon icon="papinpplc:clear" suffix on-tap="_clearLocation"></iron-icon>
|
|
171 | 215 | notify: true,
|
172 | 216 | value: "",
|
173 | 217 | observer: '_svalChanged'
|
| 218 | + }, |
| 219 | + /** |
| 220 | + * @private |
| 221 | + * The url for the google maps api |
| 222 | + */ |
| 223 | + _gmapApiUrl: { |
| 224 | + type: String, |
| 225 | + notify: true, |
| 226 | + computed: '_computeUrl(apiKey)' |
| 227 | + }, |
| 228 | + /** |
| 229 | + * @private |
| 230 | + * jsonp loaded bool |
| 231 | + */ |
| 232 | + _ijplLoaded: { |
| 233 | + type: Boolean |
174 | 234 | }
|
175 | 235 |
|
176 | 236 | },
|
|
182 | 242 | }
|
183 | 243 | },
|
184 | 244 |
|
| 245 | + _computeUrl: function(akey) { |
| 246 | + return "https://maps.googleapis.com/maps/api/js?callback=%%callback%%&v=3.exp&libraries=drawing,geometry,places,visualization&key=" |
| 247 | + + akey; |
| 248 | + }, |
| 249 | + |
185 | 250 | _mapsApiLoaded: function() {
|
186 | 251 | if (!this._geocoder && !this._places && this.$.locationsearch && this.$.locationsearch.$.nativeInput) {
|
187 | 252 | this._geocoder = new google.maps.Geocoder();
|
|
0 commit comments