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());
});
7
  • please share your code, have a look at stackoverflow.com/help/how-to-ask...welcome to SO Commented Mar 4, 2017 at 10:33
  • @Jadeye I have updated my question can you please review it. Commented Mar 4, 2017 at 10:47
  • did you google this??? plenty of information out there...stackoverflow.com/questions/28484487/… AND stackoverflow.com/questions/42234198/… Commented Mar 4, 2017 at 10:51
  • You can push each marker into an array and then serialize them to be stored in DB Commented Mar 4, 2017 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. Commented Mar 4, 2017 at 10:53

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.