1

I am new on ruby. I want to know that how can I store multiple markers in database using google maps. I want to store values of longitude and latitude in single attributes in database.

This is my controller code for storing single values in database from markers

@product.latitude = params[:product]['latitude']   
@product.longitude = params[:product]['longitude']

This is my javascript for map

google.maps.event.addListener(map, 'click', function (evt) {
  var location =  evt.latLng
  placeMarker(location);
  $("#product_latitude").val(location.lat());
  $("#product_longitude").val(location.lng());
});
Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
yawar
  • 15
  • 1
  • 7
  • please share your code, have a look at http://stackoverflow.com/help/how-to-ask...welcome to SO – Jadeye Mar 04 '17 at 10:33
  • @Jadeye I have updated my question can you please review it. – yawar Mar 04 '17 at 10:47
  • did you google this??? plenty of information out there...http://stackoverflow.com/questions/28484487/ruby-on-rails-google-maps-api-displaying-multiple-markers AND http://stackoverflow.com/questions/42234198/ruby-on-rails-geocoder-objects-as-google-map-marker-array – Jadeye Mar 04 '17 at 10:51
  • You can push each marker into an array and then serialize them to be stored in DB – theterminalguy Mar 04 '17 at 10:52
  • @Jadeye this is to show markers which are already created in database i want the user to pin multiple markers while creating a post. And i want that markers to be stored in database. – yawar Mar 04 '17 at 10:53
  • @DamianSimonPeter Can you please give me a reference that how can i do that. i am new to ruby – yawar Mar 04 '17 at 10:54
  • @yawar take a look at this SO answer https://stackoverflow.com/questions/21312278/storing-arrays-in-database-json-vs-serialized-array It clearly explains how to do it the right way. – theterminalguy Mar 04 '17 at 11:46

1 Answers1

1

As the click event happens you will send a ajax request to Controller where you can use reverse geo code and can convert these lat,lng into address and can save it . on every click new pin will be added and ajax request will called to server

Ayaz Ahmad Tarar
  • 534
  • 8
  • 24