Permalink
Browse files

More documentation for getSpeed()

Shortcuts for isPointInCircle (withinRadius) and isPointInside (isInside)
  • Loading branch information...
1 parent a97ac7a commit 15ca75a02711f8873eb6b08c40b388d6e2de201b @manuelbieh committed Feb 7, 2013
Showing with 67 additions and 25 deletions.
  1. +0 −16 README.md
  2. +1 −1 component.json
  3. +32 −3 geolib.js
  4. +3 −3 geolib.min.js
  5. +1 −1 package.json
  6. +30 −1 src/geolib.js
View
@@ -166,22 +166,6 @@ geolib.getPathLength([
{latitude: 51.503333, longitude: -0.119722} // London
]); // -> 945235</pre>
-<h3>geolib.getPathLength(mixed coords)</h3>
-
-Calculates the length of a collection of coordinates
-
-Returns the length of the path in kilometers
-
-<h4>Example</h4>
-
-<pre>
-// Calculate distance from Berlin via Dortmund to London
-geolib.getPathLength([
- {latitude: 52.516272, longitude: 13.377722}, // Berlin
- {latitude: 51.515, longitude: 7.453619}, // Dortmund
- {latitude: 51.503333, longitude: -0.119722} // London
-]); // -> 945235</pre>
-
<h3>geolib.getSpeed(coords, coords[, options])</h3>
View
@@ -35,6 +35,6 @@
"scripts": {
"test": "grunt travis --verbose"
},
- "version": "1.2.7",
+ "version": "1.2.8",
"main": "./geolib"
}
View
@@ -1,11 +1,11 @@
-/*! geolib 1.2.7 by Manuel Bieh
+/*! geolib 1.2.8 by Manuel Bieh
* A small library to provide some basic geo functions like distance calculation,
* conversion of decimal coordinates to sexagesimal and vice versa, etc.
* WGS 84 (World Geodetic System 1984)
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
-* @version 1.2.7
+* @version 1.2.8
* @license LGPL
**/
@@ -402,6 +402,13 @@
},
+ /**
+ * Shortcut for geolib.isPointInside()
+ */
+ isInside: function() {
+ return geolib.isPointInside.apply(geolib, arguments);
+ },
+
/**
* Checks whether a point is inside of a circle or not.
@@ -417,6 +424,13 @@
},
+ /**
+ * Shortcut for geolib.isPointInCircle()
+ */
+ withinRadius: function() {
+ return geolib.isPointInCircle.apply(geolib, arguments);
+ },
+
/**
* Gets rhumb line bearing of two points. Find out about the difference between rhumb line and
@@ -599,7 +613,10 @@
var coordsArray = [];
for(var coord in coords) {
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
+ });
}
return coordsArray.sort(function(a, b) { return a.distance - b.distance; });
@@ -643,12 +660,23 @@
},
+
+ /**
+ * 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);
@@ -659,6 +687,7 @@
},
+
/**
* Converts a distance from meters to km, mm, cm, mi, ft, in or yd
*
Oops, something went wrong.

0 comments on commit 15ca75a

Please sign in to comment.