Using gmaps4rails with https/SSL

倾然丶 夕夏残阳落幕 提交于 2019-12-22 10:29:07

问题


I'm a big fan of gmaps4rails - it's made adding maps to our web app very easy. The only problem I'm hitting now is that if you use it on an https page, then you get security warnings about mixed content. The google maps api does support https, so I think it's just a question of changing the script references from http to https. Unfortunately I think it's hidden behind the "acts_as_gmappable" statement - I was hoping for a content_for block I could modify.

Is there an easy way to make it use the https version of the API?

http://code.google.com/apis/maps/documentation/javascript/basics.html#HTTPS

Many thanks,

Alex


回答1:


It's not a very obvious title but your solution lies in the Miscellaneous section of the gem's wiki.

Just have a look:

<%= gmaps( data_hash, enable_css, enable_js) %>

enable_css and enable_js are booleans.

So if you do:

<%= gmaps( data_hash, true, false) %>

It won't load any js. his way you can add whatever you want by yourself. Don't forget to include the gmaps4rails.js file!




回答2:


For anyone who has a problem with the clustered markers, just change the image path of the cluster images before the initialisation of the handler:

    MarkerClusterer.IMAGE_PATH = 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/images/m';

I don't know if that's the best way, but at least it works and I hove no problem with SSL errors on my page because of the clustered markers anymore.

Update

Ok it is not the best way. Here's a better solution:

handler = Gmaps.build('Google', {
  markers: {
    clusterer: {
      imagePath: 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/images/m'
    }
  }
});


来源:https://stackoverflow.com/questions/6681310/using-gmaps4rails-with-https-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!