Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2842

Using float for lat/lng looses precision

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.2
    • Affects Version/s: None
    • Component/s: None
    • None

      I have a m which uses 2d index. When saving lat/lng, document is not created so I needed to convert it to float using to_f. For example

      location = Array.new
      if !params[:lat].blank?
        location << params[:lat].to_f
      end
      if !params[:lng].blank?
        location << params[:lng].to_f
      end
      
      item = Item.new({
        location: location
      }).save
      

      The model looks something like:

      class Item
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :location,        :type => Array
        index({ location: "2d" })
      end
      

      Problem now is data stored is rounded instead of storing the actual value that I am passing since I am using float and It concerns me that some precision on lat/lng might be lost.

      Is there a way to force Mongoid/Rails to use double type as mongodb supports double data type.

      Thanks

            Assignee:
            Unassigned Unassigned
            Reporter:
            reyjexter reyjexter
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: