Skip to content

Instantly share code, notes, and snippets.

@efwe
Created January 8, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efwe/c73ab0d887110156c2f9 to your computer and use it in GitHub Desktop.
Save efwe/c73ab0d887110156c2f9 to your computer and use it in GitHub Desktop.
def route_to
lat = params[:lat].to_f
lon = params[:lon].to_f
first_point = TrackPoint.where({:location => {'$nearSphere' => [lat, lon]}}).limit(1).first()
route = Route.find(first_point.route_id)
gjson_line = {
:type => "Feature",
:geometry => {
:type => "LineString",
:coordinates => route.track_points.map { |p| p.location }
}
}
feature_collection = {
:type => "FeatureCollection",
:features => [gjson_line]
}
render :json => Yajl::Encoder.encode(feature_collection), :content_type => 'application/json'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment