This Gem provides interaction with OSRM Server API
Add this line to your application's Gemfile:
gem 'osrm_api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install osrm_api
require 'osrm_api'
# Initialize the client.
client = OSRM::Client.new(host: 'example.com', port: 5000)
# Perform the request
distance = client.distance('40.723279,-73.937766', '40.90,-73.10', '40.82279,-73.937766')
route = client.route('40.723279,-73.937766', '40.90,-73.10', '40.823279,-73.937766')
locate = client.locate('53.911808, 27.595035')
nearest = client.nearest('53.911808, 27.595035')
To connect any special settings it’s necessary to use block construction like the following one:
route = client.route('40.723279,-73.937766', '40.90,-73.10') do |request|
request.add_param 'z', 7
end
There are 4 types of responses.
LocateObject extends base class. There arise new property @lat and @lon which contain point position.
lc = client.locate('40.723279,-73.9377')
lc.lat # => '40.723274'
lc.lon # => '-73.937408'
NearestObject extends Locate and adds new property @name, which contains the name of object on the map.
nr = client.nearest('40.723279,-73.9377')
nr.lat # => '40.723274'
nr.lon # => '-73.937408'
nr.name # => 'Anthony Street'
DistanceObject contains in the @distance_table property the amount which reflects the distance between the points of the request.
dc = client.distance('40.723279,-73.9377', '40.723279,-73.9877')
dc.distance_table # => [[0, 3551], [4116,0]]
RouteObject contains geometry, summary, instructions, name properties. If there is a necessity to get other properties of the route, you need to call to them via @orgin_response property of the parent class.
rt = client.route('40.723279,-73.9377', '40.723279,-73.9877')
rt.summary['total_time'] # => 355
- Fork it ( https://github.com/ikantam/osrm-api/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request