apneadiving / Google-Maps-for-Rails

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

Provide an example where Gmaps.map.userLocation.Lat() does not return Null. #364

Closed Merovex closed 10 years ago

Merovex commented 11 years ago

I have the following code below, which seems to come from several locations. However, nothing seems to cause Gmaps.map.userLocation to be populated. I've tried every permutation available to no avail.

A couple years ago you offered one StackOverflow user to put up an issue to get this useful feature documented. I haven't found it in your repository. Could you please document a working example? Then I can find out if I'm using borked examples or there's something borked with my app.

Thanks.


= gmaps(:map_options => {:detect_location => true, :auto_zoom => true, :auto_adjust => true}, :markers => {:data => @json} )

- content_for :scripts do
  :javascript
    Gmaps.map.callback = function() {
      Gmaps.map.createMarker({
        Lat: Gmaps.map.userLocation.lat(),
        Lng: Gmaps.map.userLocation.lng(),
        rich_marker: null,
        marker_picture: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/heart30.png"
      })
    }
apneadiving commented 10 years ago

Look here there is a callback after geolocation: https://github.com/apneadiving/Google-Maps-for-Rails/blob/1.x/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee#L27