forked from GoogleWebComponents/google-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-map-search.html
83 lines (71 loc) · 1.99 KB
/
google-map-search.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!-- Copyright (c) 2014 Google Inc. All rights reserved. -->
<link rel="import" href="../polymer/polymer.html">
<!--
Provides Google Maps Places API functionality.
See https://developers.google.com/maps/documentation/javascript/places for more
information on the API.
#### Example:
<template is="auto-binding">
<google-map-search map="{{map}}" query="Pizza"
result="{{result}}"></google-map-search>
<google-map map="{{map}}" latitude="37.779"
longitude="-122.3892"></google-map>
<div>Result: {{result.latitude}}, {{result.longitude}}</div>
</template>
<script>
document.querySelector('google-map-search').search();
</script>
@element google-map-search
@status alpha
@homepage http://googlewebcomponents.github.io/google-map/
-->
<polymer-element name="google-map-search" attributes="query result map">
<script>
Polymer('google-map-search', {
/**
* The Google map object.
*
* @attribute map
* @type google.maps.Map
* @default null
*/
map: null,
/**
* The search query.
*
* @attribute query
* @type string
* @default null
*/
query: null,
/**
* The search result.
*
* @attribute result
* @type object
*/
observe: {
query: 'search',
map: 'search'
},
/**
* Performance a search using for `query` for the search term.
*
* @method search
*/
search: function() {
if (this.query && this.map) {
var places = new google.maps.places.PlacesService(this.map);
places.textSearch({query: this.query}, this.gotResults.bind(this));
}
},
gotResults: function(results, status) {
this.result = {
latitude: results[0].geometry.location.lat(),
longitude: results[0].geometry.location.lng(),
show: true
}
}
});
</script>
</polymer-element>