Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geolib

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geolib - npm Package Compare versions

Comparing version 1.2.5 to 1.3.1

224

geolib.js

@@ -1,3 +0,3 @@

/*! geolib 1.2.5 by Manuel Bieh
* A small library to provide some basic geo functions like distance calculation,
/*! geolib 1.3.1 by Manuel Bieh
* A growing library to provide some basic geo functions like distance calculation,
* conversion of decimal coordinates to sexagesimal and vice versa, etc.

@@ -8,11 +8,13 @@ * WGS 84 (World Geodetic System 1984)

* @url http://www.manuelbieh.com/
* @version 1.2.5
* @version 1.3.1
* @license LGPL
**/
**//*global console:true geolib:true require:true module:true window:true global:true define:true*/
(function (global, undefined) {
/*global geolib:true require:true module:true window:true*/
(function (window, undefined) {
var radius = 6378137; // Earth radius
var sexagesimalPattern = /^([0-9]{1,3})°\s*([0-9]{1,3})'\s*(([0-9]{1,3}(\.([0-9]{1,2}))?)"\s*)?([NEOSW]?)$/;
var MIN_LAT = -90;
var MAX_LAT = 90;
var MIN_LON = -180;
var MAX_LON = 180;

@@ -27,2 +29,14 @@ var geolib = {

measures: {
m: 1,
km: 0.001,
cm: 100,
mm: 1000,
mi: (1 / 1609.344),
sm: (1 / 1852.216),
ft: (100 / 30.48),
"in": (100 / 2.54),
yd: (1 / 0.9144)
},
/**

@@ -359,2 +373,54 @@ * Get the key names for a geo point.

/**
* Computes the bounding coordinates of all points on the surface
* of the earth less than or equal to the specified great circle
* distance.
*
* @param object Point position {latitude: 123, longitude: 123}
* @param number Distance (in meters).
* @return array Collection of two points defining the SW and NE corners.
*/
getBoundsOfDistance: function(point, distance) {
var keys = geolib.getKeys(point);
var latitude = keys.latitude;
var longitude = keys.longitude;
var coord = {};
coord[latitude] = geolib.useDecimal(point[latitude]);
coord[longitude] = geolib.useDecimal(point[longitude]);
var radLat = coord[latitude].toRad();
var radLon = coord[longitude].toRad();
var radDist = distance / radius;
var minLat = radLat - radDist;
var maxLat = radLat + radDist;
var MAX_LAT_RAD = MAX_LAT.toRad();
var MIN_LAT_RAD = MIN_LAT.toRad();
var MAX_LON_RAD = MAX_LON.toRad();
var MIN_LON_RAD = MIN_LON.toRad();
var minLon, maxLon;
if (minLat > MIN_LAT_RAD && maxLat < MAX_LAT_RAD) {
var deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat));
minLon = radLon - deltaLon;
if (minLon < MIN_LON_RAD) {
minLon += 2 * Math.PI;
}
maxLon = radLon + deltaLon;
if (maxLon > MAX_LON_RAD) {
maxLon -= 2 * Math.PI;
}
} else {
// A pole is within the distance.
minLat = Math.max(minLat, MIN_LAT_RAD);
maxLat = Math.min(maxLat, MAX_LAT_RAD);
minLon = MIN_LON_RAD;
maxLon = MAX_LON_RAD;
}
return [
// Southwest
{"latitude": minLat.toDeg(), "longitude": minLon.toDeg()},
// Northeast
{"latitude": maxLat.toDeg(), "longitude": maxLon.toDeg()}
];
},
/**
* Checks whether a point is inside of a polygon or not.

@@ -396,3 +462,10 @@ * Note that the polygon coords must be in correct order!

/**
* Shortcut for geolib.isPointInside()
*/
isInside: function() {
return geolib.isPointInside.apply(geolib, arguments);
},
/**

@@ -412,3 +485,10 @@ * Checks whether a point is inside of a circle or not.

/**
* Shortcut for geolib.isPointInCircle()
*/
withinRadius: function() {
return geolib.isPointInCircle.apply(geolib, arguments);
},
/**

@@ -595,3 +675,6 @@ * Gets rhumb line bearing of two points. Find out about the difference between rhumb line and

var d = geolib.getDistance(latlng, coords[coord]);
coordsArray.push({key: coord, latitude: coords[coord][latitude], longitude: coords[coord][longitude], distance: d});
coordsArray.push({
key: coord, latitude: coords[coord][latitude],
longitude: coords[coord][longitude], distance: d
});
}

@@ -640,3 +723,31 @@

/**
* Calculates the speed between to points within a given time span.
*
* @param object coords with javascript timestamp {latitude: 51.5143, longitude: 7.4138, time: 1360231200880}
* @param object coords with javascript timestamp {latitude: 51.5502, longitude: 7.4323, time: 1360245600460}
* @param object options (currently "unit" is the only option. Default: km(h));
* @return float speed in *unit* per hour
*/
getSpeed: function(start, end, options) {
var unit = options && options.unit || 'km';
if(unit == 'mph') {
unit = 'mi';
} else if(unit == 'kmh') {
unit = 'km';
}
var distance = geolib.getDistance(start, end);
var time = ((end.time*1)/1000) - ((start.time*1)/1000);
var mPerHr = (distance/time)*3600;
var speed = Math.round(mPerHr * geolib.measures[unit] * 10000)/10000;
return speed;
},
/**
* Converts a distance from meters to km, mm, cm, mi, ft, in or yd

@@ -665,26 +776,8 @@ *

switch(unit) {
case 'm': // Meter
return geolib.round(distance, round);
case 'km': // Kilometer
return geolib.round(distance / 1000, round);
case 'cm': // Centimeter
return geolib.round(distance * 100, round);
case 'mm': // Millimeter
return geolib.round(distance * 1000, round);
case 'mi': // Miles
return geolib.round(distance * (1 / 1609.344), round);
case 'sm': // Seamiles
return geolib.round(distance * (1 / 1852.216), round);
case 'ft': // Feet
return geolib.round(distance * (100 / 30.48), round);
case 'in': // Inch
return geolib.round(distance * 100 / 2.54, round);
case 'yd': // Yards
return geolib.round(distance * (1 / 0.9144), round);
if(typeof geolib.measures[unit] !== 'undefined') {
return geolib.round(distance * geolib.measures[unit], round);
} else {
throw new Error('Unknown unit for conversion.');
}
return distance;
},

@@ -796,27 +889,4 @@

if (typeof(Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function() {
return this * Math.PI / 180;
};
}
/* Optional elevation addon requires Googlemaps API JS */
if (typeof(Number.prototype.toDeg) === "undefined") {
Number.prototype.toDeg = function() {
return this * 180 / Math.PI;
};
}
// we're in a browser
window.geolib = geolib;
if (typeof module != 'undefined') {
module.exports = geolib;
}
}(this));
(function(global) {
var geolib = global.geolib;
/* Optional elevation addon requires Googlemaps API JS */
/*global google:true geolib:true require:true module:true elevationResult*/

@@ -956,2 +1026,46 @@ /**

})(this);
if (typeof(Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function() {
return this * Math.PI / 180;
};
}
if (typeof(Number.prototype.toDeg) === "undefined") {
Number.prototype.toDeg = function() {
return this * 180 / Math.PI;
};
}
/*
// we're in a browser
window.geolib = geolib;
if (typeof module != 'undefined') {
module.exports = geolib;
}
*/
if (typeof module != 'undefined') {
// Node module
global.geolib = module.exports = geolib;
} else if (typeof define === "function" && define.amd) {
// AMD module
define("geolib", [], function () {
return geolib;
});
// what's the difference to:
//define(function() { return geolib; });
// ?
} else {
// we're in a browser, yay
global.geolib = geolib;
}
}(this));
{
"name": "geolib",
"homepage": "http://github.com/manuelbieh/Geolib",
"author": {
"name": "Manuel Bieh",
"url": "http://www.manuelbieh.com/"
},
"bin": {
"geolib": "./geolib.js"
},
"repository": {
"type": "git",
"url": "http://github.com/manuelbieh/geolib.git"
},
"devDependencies": {
"grunt": ">=0.3.9"
},
"licenses": [
{
"type": "LGPL",
"url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
}
],
"files": [
"geolib.js"
],
"description": "Library to perform geo specific tasks",
"keywords": [
"geolocation",
"geo",
"distance"
],
"scripts": {
"test": "grunt travis --verbose"
},
"version": "1.2.5",
"main": "./geolib"
}
"name": "geolib",
"homepage": "http://github.com/manuelbieh/Geolib",
"author": {
"name": "Manuel Bieh",
"url": "http://www.manuelbieh.com/"
},
"bin": {
"geolib": "./geolib.js"
},
"repository": {
"type": "git",
"url": "http://github.com/manuelbieh/geolib.git"
},
"devDependencies": {
"grunt": "~0.4",
"grunt-cli": "*",
"grunt-contrib-uglify": "~0.2",
"grunt-contrib-concat": "~0.3",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-copy": "~0.4",
"grunt-contrib-qunit": "~0.2.0",
"grunt-text-replace": "~0.3.6",
"grunt-contrib-jshint": "~0.6.2",
"phantomjs": "~1.8.0",
"grunt-jslint": "~1.0.0"
},
"licenses": [
{
"type": "LGPL",
"url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
}
],
"files": [
"geolib.js"
],
"description": "Library to perform geo specific tasks",
"keywords": [
"geolocation",
"geo",
"distance"
],
"scripts": {
"test": "grunt travis --verbose"
},
"version": "1.3.1",
"main": "./geolib"
}

@@ -8,5 +8,5 @@ # Geolib

## Methods
<h2>Methods</h2>
### geolib.getDistance(object start, object end, [int accuracy])
<h3>geolib.getDistance(object start, object end[, int accuracy])</h3>

@@ -19,3 +19,3 @@ Calculates the distance between two geo coordinates

#### Examples
<h4>Examples</h4>

@@ -48,3 +48,3 @@ <pre>geolib.getDistance(

### geolib.getCenter(array coords)
<h3>geolib.getCenter(array coords)</h3>

@@ -57,3 +57,3 @@ Calculates the geographical center of all points in a collection of geo coordinates

#### Examples
<h4>Examples</h4>

@@ -78,3 +78,3 @@ <pre>var spots = {

### geolib.isPointInside(object latlng, array coords)
<h3>geolib.isPointInside(object latlng, array coords)</h3>

@@ -86,3 +86,3 @@ Checks whether a point is inside of a polygon or not.

#### Example
<h4>Example</h4>

@@ -139,7 +139,7 @@ <pre>

### geolib.findNearest(object latlng, mixed coords, int offset)
<h3>geolib.findNearest(object latlng, mixed coords[, int offset])</h3>
Finds the nearest coordinate to a reference coordinate.
#### Examples
<h4>Examples</h4>

@@ -160,3 +160,3 @@ <pre>var spots = {

### geolib.getPathLength(mixed coords)
<h3>geolib.getPathLength(mixed coords)</h3>

@@ -167,3 +167,3 @@ Calculates the length of a collection of coordinates

#### Example
<h4>Example</h4>

@@ -178,7 +178,25 @@ <pre>

### geolib.convertUnit(string unit, float distance, [int round])
<h3>geolib.getSpeed(coords, coords[, options])</h3>
Calculates the speed between to points within a given time span.
Returns the speed in <em>options.unit</em> (default is km/h).
<h4>Example</h4>
<pre>
geolib.getSpeed(
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
{lat: 52.54944, lng: 13.468509, time: 1360245600880},
{unit: 'mph'}
); // -> 66.9408 (mph)</pre>
<h3>geolib.convertUnit(string unit, float distance[, int round])</h3>
Converts a given distance (in meters) to another unit.
#### Parameters
<h4>Parameters</h4>

@@ -201,15 +219,15 @@ `unit` can be one of:

#### Example
<h4>Example</h4>
`geolib.convertUnit('km', 14213, 2) // -> 14,21`
### geolib.sexagesimal2decimal(string coord)
<h3>geolib.sexagesimal2decimal(string coord)</h3>
Converts a sexagesimal coordinate to decimal format
#### Example
<h4>Example</h4>
`geolib.sexagesimal2decimal("51° 29' 46\" N")`
### geolib.decimal2sexagesimal(float coord)
<h3>geolib.decimal2sexagesimal(float coord)</h3>

@@ -219,3 +237,3 @@ Converts a decimal coordinate to sexagesimal format

#### Example
<h4>Example</h4>

@@ -225,8 +243,8 @@ `geolib.decimal2sexagesimal(51.49611111); // -> 51° 29' 46.00`

### geolib.useDecimal(mixed coordinate)
<h3>geolib.useDecimal(mixed coordinate)</h3>
Checks if a coordinate is already in decimal format and, if not, converts it to
#### Example
<h4>Example</h4>
<pre>geolib.useDecimal("51° 29' 46\" N"); // -> 51.59611111
geolib.useDecimal(51.59611111) // -> 51.59611111</pre>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc