apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Custom Marker not being displayed #541

Closed nccmike closed 7 years ago

nccmike commented 7 years ago

I am trying to add some markers after initial map creation. I first create the map with a custom marker and that is displayed as expected.

I then try to add markers and the custom marker (a different icon from the first) is not displayed. The source on the page seems to show that it is finding the image to use as you can see in the code the lat/lng and image src are present.

<script type="text/javascript">
  handler = Gmaps.build('Google');
  handler.buildMap({ 
    provider: {}, internal: {id: 'map'}}, function(){
      markers = handler.addMarkers([
        {
          "lat": 34.0754,
          "lng": -84.2941,
          "picture": {
            "url": '/assets/fpd_gmaps_icon-1bd219609b13b8e79c603011fd6d1bb56949eb0c91f14e7ca1495c2caeea90c9.png',
            "width":  32,
            "height": 32
          },
          "infowindow": "hello!"
        }
    ]);
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds();
    handler.getMap().setZoom(5);
  });
</script>
<script>
  markers = handler.addMarkers([{"lat":34.189234,"lng":-80.178932,"picture":{"url":"/assets/lead-446904bd13695a499af504dac0f6bde45d9d1a6e8c79e42a8c8329a21331d527.png"}}]);
</script>

I do see an error in the console: Uncaught TypeError: Cannot read property 'addMarker' of undefined

However, if I remove the custom picture from the second marker, it displays a standard marker even with the error seen above.

apneadiving commented 7 years ago

I'm unsure what the problem is and its tricky to solve without a plunkr or alike. But at first glance you pass url in picture but no dimensions which is prone to fail :)

nccmike commented 7 years ago

That was exactly the issue... Thank you @apneadiving