1

I have relatively old app written in RoR which I am maintaining on regular basis now running Rails 4.2.6 and Ruby 2.3.0 I am also using gmaps4rails to display various markers on a map. Suddenly the maps are no longer rendered. I am assuming that this is happening due to some deprecated versions.

Here are the lines in the application.html.erb file:

    <script src="https://maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
<script src="https://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js" type="text/javascript"></script>
<script src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js" type="text/javascript"></script>
    <script src="https://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js" type="text/javascript"></script>

All I want to know is how to have these links updated to some new versions such a why to get back the maps rendered? Changing the entire app code significantly is not a good option here.

L.D
  • 1,279
  • 3
  • 15
  • 31

1 Answers1

4

As Google moved the sources over to GitHub a while back, the new GitHub versions can be accessed from RawGit by using the following script urls:

https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/src/markerclusterer.js
https://cdn.rawgit.com/googlemaps/v3-utility-library/master/richmarker/src/richmarker-compiled.js
https://cdn.rawgit.com/googlemaps/v3-utility-library/master/infobox/src/infobox_packed.js

The above MarkerClusterer script url links to the standard version of the library as the packed version has been removed from the master branch. If you'd still like to access the packed version, this can be done by targeting the 2.1.2 release of the library as covered below.

You may also need to specify the imagePath option when instantiating your MarkerClusterer to access the images from GitHub:

var mc = new MarkerClusterer(map, markers, { 
    imagePath: 'https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m' 
});

The following earlier SO post contains more detail regarding the imagePath reference to the cluster images (whilst it refers to the MarkerClusterer library the details should also apply to the MarkerClustererPlus library):

Google maps not working in https://

Whilst the above urls (with the cdn prefixes) have no traffic limits or throttling and the files are served via a super fast global CDN, please bear in mind that RawGit is a free hosting service and offers no uptime or support guarantees.

Accessing files maintained via GitHub is covered in more detail in the following SO answer:

Link and execute external JavaScript file hosted on GitHub

This post also covers that, if you're linking to files on GitHub, in production you should consider targeting a specific release tag to ensure you're getting a specific release version of the script.

For example, you could target the 2.1.2 release of the MarkerClustererPlus library (which still includes the packed version) and the 1.1.13 release of the InfoBox library with the following script urls:

https://cdn.rawgit.com/googlemaps/v3-utility-library/markerclustererplus/2.1.2/src/markerclusterer_packed.js
https://cdn.rawgit.com/googlemaps/v3-utility-library/infobox/1.1.13/src/infobox_packed.js

However, as the custodians of this GitHub repository have yet to create any releases for the RichMarker library, it isn't currently possible to link directly to a specific RichMarker release.

In this case, you should seriously consider downloading and including the library and its resources directly in your project for production purposes.

Community
  • 1
  • 1
Chris Cook
  • 2,821
  • 1
  • 20
  • 32
  • Thanks but what about the first line, that containing the main stuff " .../maps/api/js?v=3.13 ...." ? – L.D May 12 '16 at 21:37
  • @L.D That reference should still be fine and dandy. I've also added a bit more info to my answer regarding the marker clusterer – Chris Cook May 12 '16 at 21:40
  • It worked perfect even after upgrading to version v=3.2.3 and removing the sensor=false and adding an app_key. But don't know where that piece of code var mc = new MarkerClusterer(map, markers, { imagePath: 'https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m' }); shall be used since I have nowhere used something similar before? – L.D May 12 '16 at 22:14
  • You may need to introduce this code If you find that the clustering images like [m1.png](https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m1.png) etc. don't appear correctly. If this is the case, and you're unsure what to do, post back and I'll assist as best I can – Chris Cook May 12 '16 at 22:16
  • It works very well so far (it is rendering the map faster), nothing is missing from the map. Many thanks. I'll post back if I'll notice anything wrong. – L.D May 12 '16 at 22:23
  • I'm glad it's done the trick and, as a result, please can you mark the answer as useful – Chris Cook May 12 '16 at 22:28
  • Sure, I already made it. Not sure why is not visible on your side. – L.D May 12 '16 at 23:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111810/discussion-between-chris-cook-and-l-d). – Chris Cook May 12 '16 at 23:27