Polymer Google自动完成地址和搜索词聚合元素
我在谷歌搜索地址聚合元素,但我没能找到,所以我决定自己写。 但是我得到了google.maps作为对象,但是google.maps.places在控制台中是未定义的,下面是我的示例代码Polymer Google自动完成地址和搜索词聚合元素,polymer,Polymer,我在谷歌搜索地址聚合元素,但我没能找到,所以我决定自己写。 但是我得到了google.maps作为对象,但是google.maps.places在控制台中是未定义的,下面是我的示例代码 <script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script> <polymer-element name="google-placesearch"> <link rel="i
<script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
<polymer-element name="google-placesearch">
<link rel="import" href="../../bower_components/polymer/polymer.html">
<template>
<style>
</style>
<input id="autocomplete" placeholder="Enter your address"
type="text"></input>
</template>
<script>
Polymer('google-placesearch', {
ready: function() {
// this.autocomplete= new google.maps.places.Autocomplete(this.$.autocomplete)
console.log(this.$.autocomplete);
autocomplete=new google.maps.places.Autocomplete(this.$.autocomplete);
// console.log(autocomplete);
},
});
</script>
</polymer-element>
聚合物('google-placesearch'{
就绪:函数(){
//this.autocomplete=new google.maps.places.autocomplete(this.$.autocomplete)
console.log(this.$.autocomplete);
autocomplete=new google.maps.places.autocomplete(this.$.autocomplete);
//控制台日志(自动完成);
},
});
有一个谷歌地图搜索
元素,尽管它似乎没有使用google.maps.places.Autocomplete
API
您还需要像这样加载google地图库:。注意,有一个
googlemapsapi
组件用于加载库并获得正确的时间。有一个googlemapsearch
元素,尽管它似乎没有使用google.maps.places.Autocomplete
api
您还需要像这样加载google地图库:。注意,有一个
googlemapsapi
组件用于加载库并获得正确的时间。我使用mapsapi创建了自己的google位置搜索元素
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/google-apis/google-maps-api.html">
<polymer-element name="google-place-search" attributes="location" >
<template>
<style>
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555555;
background-color: #ffffff;
background-image: none;
border: 1px solid #cccccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
</style>
<google-maps-api apiKey="{{apiKey}}" version="{{version}}" on-api-load="{{mapApiLoaded}}" libraries="{{libraries}}"></google-maps-api>
<input id="autocomplete" placeholder="Enter your address first time"
type="text" class="form-control"></input>
</template>
<script>
Polymer('google-place-search', {
autocomplete:null,
version: '3.exp',
apiKey: null,
libraries: "places",
mapApiLoaded: function() {
this.autocomplete= new google.maps.places.Autocomplete(this.$.autocomplete);
google.maps.event.addListener(this.autocomplete, 'place_changed', function() {
var place = this.autocomplete.getPlace();
this.location=place.formatted_address
}.bind(this));
}
});
</script>
</polymer-element>
.表格管制{
显示:块;
宽度:100%;
高度:34px;
填充:6px 12px;
字体大小:14px;
线高:1.42857143;
颜色:#555555;
背景色:#ffffff;
背景图像:无;
边框:1px实心#中交;
边界半径:4px;
-webkit盒阴影:插入0 1px 1px rgba(0,0,0,0.075);
盒影:插入0 1px 1px rgba(0,0,0,0.075);
-webkit过渡:边框颜色缓进缓出.15s,框阴影缓进缓出.15s;
过渡:边框颜色淡入淡出.15s,框阴影淡入淡出.15s;
}
聚合物('google-place-search'{
自动完成:空,
版本:“3.exp”,
apiKey:null,
图书馆:“地方”,
mapApiLoaded:function(){
this.autocomplete=new google.maps.places.autocomplete(this.$.autocomplete);
google.maps.event.addListener(this.autocomplete,'place\u changed',function(){
var place=this.autocomplete.getPlace();
this.location=place.formatted\u地址
}.约束(这个);
}
});
我使用maps api创建了自己的google位置搜索元素
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/google-apis/google-maps-api.html">
<polymer-element name="google-place-search" attributes="location" >
<template>
<style>
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555555;
background-color: #ffffff;
background-image: none;
border: 1px solid #cccccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
</style>
<google-maps-api apiKey="{{apiKey}}" version="{{version}}" on-api-load="{{mapApiLoaded}}" libraries="{{libraries}}"></google-maps-api>
<input id="autocomplete" placeholder="Enter your address first time"
type="text" class="form-control"></input>
</template>
<script>
Polymer('google-place-search', {
autocomplete:null,
version: '3.exp',
apiKey: null,
libraries: "places",
mapApiLoaded: function() {
this.autocomplete= new google.maps.places.Autocomplete(this.$.autocomplete);
google.maps.event.addListener(this.autocomplete, 'place_changed', function() {
var place = this.autocomplete.getPlace();
this.location=place.formatted_address
}.bind(this));
}
});
</script>
</polymer-element>
.表格管制{
显示:块;
宽度:100%;
高度:34px;
填充:6px 12px;
字体大小:14px;
线高:1.42857143;
颜色:#555555;
背景色:#ffffff;
背景图像:无;
边框:1px实心#中交;
边界半径:4px;
-webkit盒阴影:插入0 1px 1px rgba(0,0,0,0.075);
盒影:插入0 1px 1px rgba(0,0,0,0.075);
-webkit过渡:边框颜色缓进缓出.15s,框阴影缓进缓出.15s;
过渡:边框颜色淡入淡出.15s,框阴影淡入淡出.15s;
}
聚合物('google-place-search'{
自动完成:空,
版本:“3.exp”,
apiKey:null,
图书馆:“地方”,
mapApiLoaded:function(){
this.autocomplete=new google.maps.places.autocomplete(this.$.autocomplete);
google.maps.event.addListener(this.autocomplete,'place\u changed',function(){
var place=this.autocomplete.getPlace();
this.location=place.formatted\u地址
}.约束(这个);
}
});
我通过在我的页面中导入maps api并查看maps api的mapApiLoaded事件来解决问题。我通过在我的页面中导入maps api并查看maps api的mapApiLoaded事件来解决问题