-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinput-location.html
executable file
·54 lines (47 loc) · 1.24 KB
/
input-location.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../google-apis/google-maps-api.html">
<dom-module id="input-location">
<style>
:host {
display: inline-block;
}
#input{
@apply(--input-location);
}
</style>
<template>
<google-maps-api id="maps" libraries="places" on-api-load="on_api_load"></google-maps-api>
<input id="input" class="input" type="text" value="{{value}}" />
</template>
</dom-module>
<script>
Polymer({
is: 'input-location',
properties: {
value: {
type: String,
notify: true
},
options: {
type: Object,
value: function () { return {}; }
},
place: {
type: Object,
value: function () { return {}; },
notify: true
}
},
on_api_load: function () {
this.autocomplete = new google.maps.places.Autocomplete(this.$.input, this.options);
google.maps.event.addListener(this.autocomplete, 'place_changed', this.on_change_place.bind(this));
},
on_change_place: function () {
this.place = this.autocomplete.getPlace();
if (!this.place.address_components) {
return;
}
this.value = this.place.formatted_address;
}
});
</script>