0

Trying to get gmaps to update in place once a new location is typed out. (anyone know a good tutorial for this actually? :P)

Anyways when running the Gmaps4Rails.replaceMarkerst method, I seem to bring up a js error seen when using chrome's inspection tool as seen below. any ideas?

http://stuff.saikonet.org/images/misc/2011-07-22-030217_1024x768_scrot.png

apneadiving
  • 114,565
  • 26
  • 219
  • 213
Chris Bolton
  • 2,878
  • 6
  • 38
  • 57

1 Answers1

1

Ok gotcha, your problem is not the replace_marker function.

Indeed, using the good old document-ready buddy, the google maps isn't yet created. So yep everything is failing.

That's where Gmaps4Rails.callback makes it's entry.

After the declaration of your map (for an obvious reason: Gmaps4Rails must be defined):

<% content_for :scripts do %>
<script>
Gmaps4Rails.callback = function() {
  Gmaps4Rails.replaceMarkers([{"lng": "-92.5294574", "lat": "45.1969796"}]);
};
</script>
<% end %>
apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • nice ;). only thing now is that when it replaces the markers it messes up my zoom and is super close-in.. how would I go about fixing that? – Chris Bolton Jul 22 '11 at 19:39
  • hm.. actually turning off auto_adjust no longer centers it around the marker now, I just don't want it to zoom in all the way. any way to achieve that? – Chris Bolton Jul 22 '11 at 19:45
  • you'll find the answer there: http://stackoverflow.com/questions/5821997/google-maps-ruby-on-rails-zoom-level-with-one-marker – apneadiving Jul 22 '11 at 19:49
  • :) you know what rewards then (and please, no death note!) – apneadiving Jul 22 '11 at 19:59
  • hahahahah. anyways :P. I'm also getting an unknown method error when trying to use adjust_map_to_bounds();. has this function been renamed or something similar? – Chris Bolton Jul 22 '11 at 22:01
  • hm gauging from the other post you linked I assumed adjustMapToBounds would center in on the marker but doesn't really seem to have any effect – Chris Bolton Jul 22 '11 at 22:12
  • it depends on the value of `Gmaps4Rails.map_options.auto_adjust` – apneadiving Jul 22 '11 at 22:16
  • yay I got it!! :P. only if every plugin maintainer was like you lol – Chris Bolton Jul 22 '11 at 22:21
  • google's API has changed, that's why... ask a new question if you don't find yourself in google's doc – apneadiving Jul 22 '11 at 22:21
  • I'm getting another no method error when using Gmaps4Rails.geocode.. has that been renamed too? – Chris Bolton Jul 22 '11 at 22:26
  • ohh it's a rails method not javascript. thankies once again :P – Chris Bolton Jul 22 '11 at 22:33
  • hm having it in rails instead of js actually complicates things quite a bit. is there no js equivalent? I'm basically trying to update the map as the user is typing in the text field, and not sure how to integrate a rails method into that.... – Chris Bolton Jul 22 '11 at 22:37
  • this is basically what I'm trying to get at: Gmaps4Rails.replaceMarkers(Gmaps4Rails.geocode($('#location').val())) – Chris Bolton Jul 22 '11 at 22:37
  • or even clicking a button to update is ok instead (sending info to a controller and back) but then that's rails code and I can't get a javascript variable into that :/. is there no way to update the map with a user-specified location without reloading the whole page? – Chris Bolton Jul 22 '11 at 22:54
  • ah wait no I think I have a way with the sending info to a controller method. – Chris Bolton Jul 22 '11 at 22:57
  • still kind of messy though.. would be nice to have geocoding available through js – Chris Bolton Jul 22 '11 at 22:59