Track vehicles in Rails through geocoding and mapping

I have a Rails 3.2.19 application that I would like to track on Units using geocoding and graphing on Google Maps.

I came up with a way to get the coordinates using the gem taip_parserand create a rake task that constantly listens for incoming taepa data, analyzes the latitude and longitude, and updates the vehicle model fields latitudeand longitude, From there I was able to display the locations of the vehicles using the gem gmaps4rails. The limitation of this is that you need to use the specific 3G / 4G modem that TAIP says to send lat / long to the Rails server so that the rake team can analyze it.

What I would like to do is to abandon the use of these expensive 3G / 4G modems and instead pull the coordinates from the mobile device located in the car (currently the iPad).

So, my thoughts is to use the HTML5 browser function in the browser to get the latitude and longitude of the device and somehow save it in the fields of the latitude / longitude database on the page / partial update that is currently happening through Ajax.

This will break the dependency on existing devices and allow any mobile GPS-compatible device to be compatible with this feature.

Currently, in my application, I have gmaps4railsto build units using my rake command and analyze taip data, as well geocoderas which I am testing for geocoding addresses, as they are created for a different purpose.

My questions:

- HTML5 ? HTML5 , ? , gmaps4rails

, , , , .

+4
1

, ajax Rails. Ajax , HTML5, ajax post.

:

  def update_gps
    @unit = current_user.unit
    if @unit.update_attributes(params[:unit])
      respond_to do |format|
        format.html {redirect_to mdt_path}
        format.js { render "index"}
      end
    end
  end

index.html.erb

 <div class="hidden">
    <%= form_for(@unit, :url => update_gps_mdt_index_path, :html => {:method => :post}) do |f| %>
    <%= f.text_field :latitude %>
    <%= f.text_field :longitude %>
    <%= f.button :submit %>
    <% end %>
    </div>
    <script>
      $(function() {
        setInterval(function(){
          $.getScript("/mdt");
        }, 10000);
      });

    function updateCurrentLocation(){
      navigator.geolocation.getCurrentPosition(function(position) {
      var c = position.coords
      var location = c.latitude +", "+ c.longitude
      console.log(location)
      var $updateLocationForm = $(".edit_unit")
      $("#unit_latitude").val(c.latitude)
      $("#unit_longitude").val( c.longitude)
      var data = $(".edit_unit").serialize();
    console.log(data)
    $.ajax({
    type: "POST",
    url: $(".edit_unit").attr("action"),
    data: data,
    success: function(data) {
    console.log('working: '+data);
    },
    error: function(msg) {
    console.log('not working '+msg);
    }
    });
    });
    }
    setInterval(updateCurrentLocation, 10000)
    </script>
+4

All Articles