R
R
Ruslan Galiev2014-03-19 14:57:17
JavaScript
Ruslan Galiev, 2014-03-19 14:57:17

Gmaps4rails - how to bind points to the road?

Hello
In the application I use the Gmaps4rails gem to display routes on the map. At the moment I just draw markers on the map and connect them with lines. The points are very scattered (GPS errors), so I want to tie them to the nearest road like here:
stackoverflow.com/questions/10513360/polyline-snap...
or here:
econym.org.uk/gmap/example_snappath.htm
Code:

<div class="map_container" style='width: 800px; height: 500px;'>
    <div id="map" style='width: 800px; height: 500px;'></div>
  </div>	
  <script type="text/javascript">
    jQuery(document).ready(function() {
      handler = Gmaps.build('Google', { markers: { maxRandomDistance: null } });
      handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
        markers = handler.addMarkers(<%=raw @markers.to_json %>);
        polyline = handler.addPolylines(<%=raw @polyline.to_json %>, { "strokeColor" : "#0088cc" });
        handler.bounds.extendWith(markers);
        handler.fitMapToBounds();
      });
    });
  </script>

I've tried this and that, and it doesn't work. Tell me how this can be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dron Krzh, 2014-03-25
@ walkman7

There is a ready-made example on the stack, use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question