2011-08-06 52 views
2

我已经gmaps4rails宝石之间的兼容性的问题,谷歌的地方APIgmaps4rails并自动完成谷歌的地方API不兼容

基本上,如果我把我的观点一个gmpas4rails这样的:

<%=gmaps%> 

那么这个脚本不工作了(它normaly激活user_address领域的自动完成:

$(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']); 
} 

我试着通过gmaps4rails.call_back和陈调用脚本ge脚本中的var名称...

任何想法?

回答

4

我想你打了第二个电话给谷歌的API,搞砸了。

两种解决方案在这里:

1)不包括从局部的JS:

<%= gmaps({your_hash}, true, false) %> 

,并包括所有手动js文件,但一定要记:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;libraries=geometry,places"></script> 

Here is the original partial所以你不要忘记任何文件。

2)抓住当前版本的Git和直接添加places

<%= gmaps({ "map_options" => { "libraries" => ["places"] } }) %> 

以后我会更新的宝石,因此以上版本0.10.2都会有这个包括在内。

+0

OK,我会等待下一个版本,因此,我的应用程序还没有准备好部署尚未 – alex

+0

从GitHub上的一个是很好,如果你不能等。您甚至可以看到您的代码位于gem中捆绑的测试应用程序中:https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/test/dummy/app/views/users/ index.html.erb – apneadiving

+0

对于在我的情况1.5.6第一溶液看起来像 <%= gmaps( map_options:..., 折线:..., 脚本::无 )%> –

1

实际上2)应该是

<%= gmaps({:map_options => {:libraries => ["places"]}}) %> 

因为在gmaps4rails符号的源代码来代替字符串。

,使其与字符串的工作,你不得不使用HashWithIndifferentAccess:

<%= gmaps(HashWithIndifferentAccess.new("map_options" => {"libraries" => ['places']}))%> 
相关问题