Giter Site home page Giter Site logo

osrm-api's Introduction

OsrmApi

This Gem provides interaction with OSRM Server API

Gem Version Coverage Status

Installation

Add this line to your application's Gemfile:

gem 'osrm_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install osrm_api

Usage

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

Response

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

Contributing

  1. Fork it ( https://github.com/ikantam/osrm-api/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

osrm-api's People

Contributors

igorpetuh avatar

Stargazers

Mohamad Kaakati avatar

Watchers

James Cloos avatar Sasha Kukareko avatar  avatar Vladimir Haidysh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.