2

Sorry to be newbie, but i wanna draw your attention to my problem while using gmaps4rails - great gem.

In my app there is no database backend. Actually i just want to collect markers like this:

<% markers=[]%>
<% @search.each do |dish| %>
<% if (not dish.restaurant.nil?)
    restaurant=Restaurant.where( :id  => dish.restaurant["Id"])
    markers<< {:longitude => restaurant.lng , :latitude=> restaurant.lat}
  end%>
<div id="dish_listed"><%= render 'dish_listed',  :dish => dish %></div>
<% end %>
<%= gmaps4rails(markers.to_json) %>

Unfortunately it displays a gray rectangular whithout a map *( I`ve managed to follow the steps from Wiki (i did it several times *))))

When i do

markers.to_json

i get

"[{\"longitude\":"30.252442359924316",\"latitude\":"59.92999013067258"}]" 

And i have no idea why kind of code

<%= gmaps4rails('[{\"lng\":"30.252442359924316",\"lat\":"59.92999013067258"}]') %>

doesnt work? Where should it be initialized? Or what magic steps did i forget? I also forked a project by thasuresh. Started it and the removed everything from the model, and pushed my markers there, and it displayed me just what i wanted.

But i still cant reach the same result on the project i write by my self!!!

-----And now i`m sitting here and waiting for flying tomatos *)))-----

PS rails 3.1rc5 gmaps4rails 0.10.2

BTW Could it be no gmappable model?

apneadiving
  • 114,565
  • 26
  • 219
  • 213
prikha
  • 1,853
  • 1
  • 16
  • 26
  • Seems like using the JavaScript maps API would be a good use here. http://code.google.com/apis/maps/documentation/javascript/basics.html It would remove the layer of abstraction that you have with the gmaps4rails gem and allow you to draw upon the examples that Google provides. – Devin M Aug 05 '11 at 18:44
  • While trying to figure out what`s the problem it occured that I can`t initialize gmap properely! Once i`ve created a scaffold and followed the steps from the Wiki. One map initialized, and afterwards another one might be opened. So how should i properly initialize gmaps4rails? – prikha Aug 05 '11 at 19:11
  • It might be a number of issues, thats the problem. Without knowing more I dont see the need for you to use gmaps4rails without a database backend. You can use google maps using their normal JS library, is that undesireable for any reason? – Devin M Aug 05 '11 at 19:18
  • @Devin M Its the third day i`m braking down with this problem, it seemed easyer to use a couple of lines of rubycode instead of dozens lines of js. But if i won`t suceed with this I`ll follow your recommendations – prikha Aug 05 '11 at 19:18
  • If you need help with the JS api let me know with a reply to this and a link to your new question. I am happy to help. – Devin M Aug 05 '11 at 19:21

1 Answers1

3

This works:

<%= gmaps4rails('[{"lng":"30.252442359924316","lat":"59.92999013067258"}]') %>

There are still little fixes to do for Rails 3.1, some threads are open on github.

To adjust the zoom level with one marker, check this question.

Community
  • 1
  • 1
apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • Thanks for coming! Yes, but no! It only outputs code
    code It seems like initializing wasn`t called, or failed! It only works when i have an object that acts_as_gmappable - but i din`t have a db-backend *) I`m new to rails so i appreciate your patience *)))) PS no problem with zoom. I simply have no map *(
    – prikha Aug 07 '11 at 07:38
  • Just checked all opened issues on github, downgraded to rails – prikha Aug 07 '11 at 07:50
  • Do you have all js files inside your view? any code visible on github or elsewhere? – apneadiving Aug 07 '11 at 07:51
  • Just checked opened issues on github, downgraded to rails 3.0.9 and gmaps4rails 0.9.1, but still the same problem. I have to call some gmappable model.to_gmaps4rails in the controller to get this working. server log is ok . On GitHub it is [here](https://github.com/IvanShamatov/something-secret) and gmpas4rails is called at the begining of food.html.erb view. PS Sorry for the mess inside. – prikha Aug 07 '11 at 08:22
  • see working app after changes here: https://github.com/apneadiving/something-secret/commit/b8cfcbb943eb16c9adeec89bd49be3d4cea2a028 – apneadiving Aug 07 '11 at 08:51
  • wowwwowow! How did you do that!!! I`ve applied your changes and it magickally works. I thought i tried it 10 times at least! You must be a mage*))) – prikha Aug 07 '11 at 09:30
  • thank you so much!!! As soon as i earn "enough carma" i`ll do a +1 but now i only can accept *) May i repost the complete answer? the trick was to use `code <%= gmaps({ "map_options" => { "auto_zoom" => false}, "markers" => { "data" => @markers.to_json } }) %>` – prikha Aug 07 '11 at 09:40
  • Ok, I see. As you feel for the answer. The only point was to upgrade the gem. Other stuff is for zoom – apneadiving Aug 07 '11 at 09:51