GpsUtils

Build Status Code Climate Test Coverage

Small ruby library for working with GPS coordinates.

Contents

Installation

You can install the package from rubygems or github using Bundler or create your own package from the source code.

Using Bundler with rubygems

Edit you Gemfile and add the following line:

gem 'gpsutils'

Then run:

$ bundle install

Using Bundler with github

Edit you Gemfile and add the following line:

gem 'gpsutils', :git => 'https://github.com/megamoose/gpsutils.git'

Then run:

$ bundle install

Using locally build gem-file

Clone the repository from github:

$ git clone https://github.com/megamoose/gpsutils.git gpsutils
$ cd gpsutils

Build the gem-file:

$ gem build gpsutils.gemspec

Install the gem-file:

$ gem install gpsutils-*.gem

Usage

Determine whether or not a given location (point) is within an area (bounding box):

# Follow instructions in the installation section.
require 'gpsutils'

# Latitude, Longitude.
location = GpsUtils::Point.new(-22.955776, -43.536438)

# North-West corner.
nw = GpsUtils::Point.new(-22.746120, -43.795060)
# South-East corner.
se = GpsUtils::Point.new(-23.076347, -43.101608)

# North-West point, South-East point.
area = GpsUtils::BoundingBox.new(nw, se)

area.cover? location

Sort positions (Points) by distance to location (Point):

# Follow instructions in the installation section.
require 'gpsutils'

# Latitude, Longitude.
location = GpsUtils::Point.new(-22.955776, -43.536438)

positions = []
positions.push(GpsUtils::Point.new(-23.560112, -46.642043))
positions.push(GpsUtils::Point.new(-12.994417, -38.508040))

positions.sort_by! do |position|
    location.distance(position)
end

License

This code is free to use under the terms of the MIT license.