3

I have been trying to get a custom use of gmaps4rails running, and I have the code set to display my string of json coordinates on the map, and the center on user IS working, I can zoom into my location from home, work and my phone. I just cannot get the js right to display an 'Im here' button on the map once permission is given.

here is the code I use for the map from gmaps4rails:

<%= gmaps(:map_options => {:detect_location => true, :center_on_user => true, :auto_zoom => false, :zoom => 12, :auto_adjust => true}, :markers => {:data => @json} ) %>

Thanks for any help!

EDIT Dec.6 after answer:

I am adding in the code for the callback as so:

        <script type="text/javascript" charset="utf-8">
         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"
                   })
                }
        </script>

and still not getting a response on the map. Is this a problem with my js coding? I'm not pro yet.

thanks!

keade
  • 137
  • 1
  • 11
  • Sorry, I don't really understand your question – apneadiving Dec 06 '11 at 18:57
  • @apneadiving THanks for reading it, I will rephrase: Trying to display a marker for the Gmaps4rails.map.userLocation data. Currently the map will center on user, but does not display a marker. ie: like at a mall/airport the "You are Here" arrow. hope that helps? – keade Dec 06 '11 at 19:43
  • ok gotcha, don't forget to accept the answer (new user notice) – apneadiving Dec 06 '11 at 20:05
  • updated the question with current code and not sure what's going on now. thanks so much for putting up with this! – keade Dec 06 '11 at 21:15
  • I think I understand why: userLocation isn't available when the callback is triggered because it has an unpredictable delay. You should use `setInterval` to loop until it's filled (of course, use `clearInterval` once done) – apneadiving Dec 06 '11 at 21:50
  • 2
    What was the final code for this? I'm trying to do something similar to add a marker with current location. – locoboy Nov 24 '12 at 06:47

1 Answers1

2

You can do this:

Gmaps.map.createMarker({Lat: Gmaps.map.userLocation.lat(),
                        Lng: Gmaps.map.userLocation.lng(), 
                        rich_marker: null, 
                        marker_picture: ""
                       })

in the callback.


Notice you can pass the url of your desired marker.

BTW, you should create an issue on github if you feel like this is a useful feature.

apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • Will give this a shot! Thanks! and to save your github issue list, will see if people traffic this Q first before listing? – keade Dec 06 '11 at 20:18