gmaps4rails和自动填充google地方API不兼容 [英] gmaps4rails and autocomplete google place API incompatibility
问题描述
我在gmaps4rails gem和google place API之间存在兼容性问题基本上,如果我将gmpas4rails放在我的视图中:
<%= gmaps%>
然后这个脚本不再工作了(它在user_address字段上正常激活一个自动完成:
$(document).ready(initialize_gmaps_autocomplete_user_address());
函数initialize_gmaps_autocomplete_user_address(){
var input = document.getElementById('user_address');
var defaultBounds = new google.maps.LatLngBounds(new google.maps.LatLng(42.71422,-4.222666),new google.maps.LatLng(51.179343,8.47412));
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.setBounds(defaultBounds);
autocomplete.setTypes(['geocode']);
}
我尝试通过gmaps4rails.call_back调用脚本并更改脚本中的var名称...
有什么想法?
第二次调用google api会搞砸了。
这里有两个解决方案:
<
<%= gmaps({your_hash},true,假)%>
并手动包含所有js文件,但一定要写下:
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false& ;库=几何,地点>< /脚本>
这是原始的部分,所以你不要忘记任何文件。
2)在git上抓取当前版本并直接添加 places
:
<%= gmaps({map_options=> {libraries=> [places]}})%>
我稍后会更新gem,所以 0.10.2
将包含此项。
I've a problem of compatibility between gmaps4rails gem and google place API
Basically if I put in my view a gmpas4rails like this:
<%=gmaps%>
then this script doesnt work anymore (it normaly activate an autocomplete on user_address field:
$(document).ready(initialize_gmaps_autocomplete_user_address());
function initialize_gmaps_autocomplete_user_address() {
var input = document.getElementById('user_address');
var defaultBounds = new google.maps.LatLngBounds(new google.maps.LatLng(42.71422,-4.222666), new google.maps.LatLng(51.179343,8.47412));
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.setBounds(defaultBounds);
autocomplete.setTypes(['geocode']);
}
I've tried to call the script by gmaps4rails.call_back and to change the var names in my scripts...
Any idea?
I guess you make a second call to the google api which mess things up.
Two solutions here:
1) don't include the js from the partial:
<%= gmaps({your_hash}, true, false) %>
And include all the js files manually but be sure to write:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry,places"></script>
Here is the original partial so you don't forget any file.
2) Grab the current version on git and add places
directly:
<%= gmaps({ "map_options" => { "libraries" => ["places"] } }) %>
I'll update the gem later, so versions above 0.10.2
will have this included.
这篇关于gmaps4rails和自动填充google地方API不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!