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 2.0.14 to 2.0.16

LICENSE

4

dist/geolib.elevation.js

@@ -1,2 +0,2 @@

/*! geolib.elevation 2.0.14 by Manuel Bieh
/*! geolib.elevation 2.0.16 by Manuel Bieh
*

@@ -7,3 +7,3 @@ * Elevation Addon for Geolib.js

* @url http://www.manuelbieh.com/
* @version 2.0.14
* @version 2.0.16
* @license MIT

@@ -10,0 +10,0 @@ */

@@ -1,2 +0,2 @@

/*! geolib 2.0.14 by Manuel Bieh
/*! geolib 2.0.16 by Manuel Bieh
* Library to provide geo functions like distance calculation,

@@ -8,3 +8,3 @@ * conversion of decimal coordinates to sexagesimal and vice versa, etc.

* @url http://www.manuelbieh.com/
* @version 2.0.14
* @version 2.0.16
* @license MIT

@@ -20,3 +20,3 @@ **/;(function(global, undefined) {

version: {
value: "2.0.14"
value: "2.0.16"
},

@@ -61,3 +61,7 @@ radius: {

if(typeof geolib.prototype[prop] === 'undefined' || overwrite === true) {
geolib.prototype[prop] = methods[prop];
if(typeof methods[prop] === 'function' && typeof methods[prop].bind === 'function') {
geolib.prototype[prop] = methods[prop].bind(geolib);
} else {
geolib.prototype[prop] = methods[prop];
}
}

@@ -69,3 +73,3 @@ }

if (typeof(Number.prototype.toRad) === "undefined") {
if (typeof(Number.prototype.toRad) === 'undefined') {
Number.prototype.toRad = function() {

@@ -76,3 +80,3 @@ return this * Math.PI / 180;

if (typeof(Number.prototype.toDeg) === "undefined") {
if (typeof(Number.prototype.toDeg) === 'undefined') {
Number.prototype.toDeg = function() {

@@ -188,2 +192,8 @@ return this * 180 / Math.PI;

// Alias for coords
ll: function(point, raw) {
return this.coords.call(this, point, raw);
},
// checks if a variable contains a valid latlong object

@@ -409,7 +419,7 @@ validate: function(point) {

/**
/**
* Calculates the center of a collection of geo coordinates
*
* @param array Collection of coords [{latitude: 51.510, longitude: 7.1321}, {latitude: 49.1238, longitude: "8° 30' W"}, ...]
* @return object {latitude: centerLat, longitude: centerLng, distance: diagonalDistance}
* @return object {latitude: centerLat, longitude: centerLng}
*/

@@ -422,47 +432,32 @@ getCenter: function(coords) {

var max = function( array ){
return Math.max.apply( Math, array );
};
var X = 0.0;
var Y = 0.0;
var Z = 0.0;
var lat, lon, hyp;
var min = function( array ){
return Math.min.apply( Math, array );
};
coords.forEach(function(coord) {
lat = coord.latitude * Math.PI / 180;
lon = coord.longitude * Math.PI / 180;
var latitude;
var longitude;
var splitCoords = {latitude: [], longitude: []};
X += Math.cos(lat) * Math.cos(lon);
Y += Math.cos(lat) * Math.sin(lon);
Z += Math.sin(lat);
});
for(var coord in coords) {
var nb_coords = coords.length;
X = X / nb_coords;
Y = Y / nb_coords;
Z = Z / nb_coords;
splitCoords.latitude.push(
this.latitude(coords[coord])
);
lon = Math.atan2(Y, X);
hyp = Math.sqrt(X * X + Y * Y);
lat = Math.atan2(Z, hyp);
splitCoords.longitude.push(
this.longitude(coords[coord])
);
return {
latitude: (lat * 180 / Math.PI).toFixed(6),
longitude: (lon * 180 / Math.PI).toFixed(6)
};
},
}
var minLat = min(splitCoords.latitude);
var minLon = min(splitCoords.longitude);
var maxLat = max(splitCoords.latitude);
var maxLon = max(splitCoords.longitude);
latitude = ((minLat + maxLat)/2).toFixed(6);
longitude = ((minLon + maxLon)/2).toFixed(6);
// distance from the deepest left to the highest right point (diagonal distance)
var distance = this.convertUnit('km', this.getDistance({latitude: minLat, longitude: minLon}, {latitude: maxLat, longitude: maxLon}));
return {
latitude: latitude,
longitude: longitude,
distance: distance
};
},
/**

@@ -618,3 +613,79 @@ * Gets the max and min, latitude, longitude, and elevation (if provided).

/**
* Pre calculate the polygon coords, to speed up the point inside check.
* Use this function before calling isPointInsideWithPreparedPolygon()
* @see Algorythm from http://alienryderflex.com/polygon/
* @param array array with coords e.g. [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
*/
preparePolygonForIsPointInsideOptimized: function(coords) {
for(var i = 0, j = coords.length-1; i < coords.length; i++) {
if(this.longitude(coords[j]) === this.longitude(coords[i])) {
coords[i].constant = this.latitude(coords[i]);
coords[i].multiple = 0;
} else {
coords[i].constant = this.latitude(coords[i]) - (
this.longitude(coords[i]) * this.latitude(coords[j])
) / (
this.longitude(coords[j]) - this.longitude(coords[i])
) + (
this.longitude(coords[i])*this.latitude(coords[i])
) / (
this.longitude(coords[j])-this.longitude(coords[i])
);
coords[i].multiple = (
this.latitude(coords[j])-this.latitude(coords[i])
) / (
this.longitude(coords[j])-this.longitude(coords[i])
);
}
j=i;
}
},
/**
* Checks whether a point is inside of a polygon or not.
* "This is useful if you have many points that need to be tested against the same (static) polygon."
* Please call the function preparePolygonForIsPointInsideOptimized() with the same coords object before using this function.
* Note that the polygon coords must be in correct order!
*
* @see Algorythm from http://alienryderflex.com/polygon/
*
* @param object coordinate to check e.g. {latitude: 51.5023, longitude: 7.3815}
* @param array array with coords e.g. [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
* @return bool true if the coordinate is inside the given polygon
*/
isPointInsideWithPreparedPolygon: function(point, coords) {
var flgPointInside = false,
y = this.longitude(point),
x = this.latitude(point);
for(var i = 0, j = coords.length-1; i < coords.length; i++) {
if ((this.longitude(coords[i]) < y && this.longitude(coords[j]) >=y ||
this.longitude(coords[j]) < y && this.longitude(coords[i]) >= y)) {
flgPointInside^=(y*coords[i].multiple+coords[i].constant < x);
}
j=i;
}
return flgPointInside;
},
/**

@@ -1159,2 +1230,2 @@ * Shortcut for geolib.isPointInside()

}(this));
}(this));

@@ -22,3 +22,3 @@ {

"grunt-contrib-jshint": "~0.6.2",
"phantomjs": "~1.8.0",
"phantomjs": ">=1.8.0",
"grunt-jslint": "~1.0.0",

@@ -51,4 +51,4 @@ "time-grunt": "~0.3.1",

},
"version": "2.0.14",
"version": "2.0.16",
"main": "dist/geolib.js"
}

@@ -1,2 +0,2 @@

# Geolib v2.0.14
# Geolib v2.0.16
[![Build Status](https://secure.travis-ci.org/manuelbieh/Geolib.png?branch=master)](http://travis-ci.org/manuelbieh/Geolib)

@@ -14,3 +14,3 @@

Takes 2 or 3 arguments. First 2 arguments must be an object with latitude and a longitude properties (e.g. `{latitude: 52.518611, longitude: 13.408056}`). Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distance of 1248 meters with an accuracy of 100 is returned as `1200` (accuracy 10 = `1250` etc.).
Takes 2 or 3 arguments. First 2 arguments must be objects that each have latitude and longitude properties (e.g. `{latitude: 52.518611, longitude: 13.408056}`)Works with:. Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distaWorks with:nce of 1248 meters with an accuracy of 100 is returned as `1200` (accuracy 10 = `1250` etc.).

@@ -22,7 +22,7 @@ Return value is always an integer and represents the distance in meters.

<pre>geolib.getDistance(
{latitude: 51.5103, longitude: 7.49347},
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}
);
geolib.getDistance(
{latitude: 51.5103, longitude: 7.49347},
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}

@@ -35,9 +35,9 @@ );

alert('You are ' + geolib.getDistance(position.coords, {
latitude: 51.525,
latitude: 51.525,
longitude: 7.4575
}) + ' meters away from 51.525, 7.4575');
},
function() {
},
function() {
alert('Position could not be determined.')
},
},
{

@@ -72,4 +72,4 @@ enableHighAccuracy: true

geolib.getCenter([
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.515, longitude: 7.453619},
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.515, longitude: 7.453619},
{latitude: 51.503333, longitude: -0.119722}

@@ -81,3 +81,3 @@ ]);

Checks whether a point is inside of a polygon or not.
Checks whether a point is inside of a polygon or not.
Note: the polygon coords must be in correct order!

@@ -91,3 +91,3 @@

geolib.isPointInside(
{latitude: 51.5125, longitude: 7.485},
{latitude: 51.5125, longitude: 7.485},
[

@@ -103,3 +103,3 @@ {latitude: 51.50, longitude: 7.40},

Similar to is point inside: checks whether a point is inside of a circle or not.
Similar to is point inside: checks whether a point is inside of a circle or not.

@@ -113,3 +113,3 @@ Returns true or false

{latitude: 51.525, longitude: 7.4575},
{latitude: 51.5175, longitude: 7.4678},
{latitude: 51.5175, longitude: 7.4678},
5000

@@ -129,4 +129,4 @@ );</pre>

geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, [
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.518, longitude: 7.45425},
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.518, longitude: 7.45425},
{latitude: 51.503333, longitude: -0.119722}

@@ -137,4 +137,4 @@ ]);

geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, {
a: {latitude: 52.516272, longitude: 13.377722},
b: {latitude: 51.518, longitude: 7.45425},
a: {latitude: 52.516272, longitude: 13.377722},
b: {latitude: 51.518, longitude: 7.45425},
c: {latitude: 51.503333, longitude: -0.119722}

@@ -161,3 +161,3 @@ });

// in this case set offset to 1 otherwise the nearest point will always be your reference point
geolib.findNearest(spots['Dortmund U-Tower'], spots, 1)
geolib.findNearest(spots['Dortmund U-Tower'], spots, 1)
</pre>

@@ -191,3 +191,3 @@

geolib.getSpeed(
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
{lat: 52.54944, lng: 13.468509, time: 1360245600880},

@@ -246,4 +246,4 @@ {unit: 'mph'}

Works with:
- latitude: `latitude`, `lat`, 0 (GeoJSON array)
- longitude: `longitude`, `lng`, `lon`, 1 (GeoJSON array)
- longitude: `longitude`, `lng`, `lon`, 0 (GeoJSON array)
- latitude: `latitude`, `lat`, 1 (GeoJSON array)
- elevation: `elevation`, `elev`, `alt`, `altitude`, 2 (GeoJSON array)

@@ -275,2 +275,2 @@

- New folder structure: compiled `geolib.js` can now be found in `dist/` instead of root dir
- Improved Grunt build task
- Improved Grunt build task
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