# manuelbieh/Geolib

manuelbieh committed Dec 1, 2012
1 parent bb3cc3d commit e00472e9d5c1ae2b97d79868092a76a95d453073
Showing with 44 additions and 23 deletions.
2. +2 −2 geolib.js
3. +2 −2 geolib.min.js
4. +1 −1 grunt.js
5. +1 −1 package.json
 @@ -7,7 +7,7 @@ A small library to provide some basic geo functions like distance calculation, c ## Methods -### getDistance(object start, object end, [int accuracy]) +### geolib.getDistance(object start, object end, [int accuracy]) Calculates the distance between two geo coordinates @@ -17,16 +17,33 @@ Return value is always an integer and represents the distance in meters. #### Examples -
geolib.getDistance({latitude: 51.5103, longitude: 7.49347}, {latitude: "51° 31' N", longitude: "7° 28' E"});
-geolib.getDistance({latitude: 51.5103, longitude: 7.49347}, {latitude: "51° 31' N", longitude: "7° 28' E"});
+
geolib.getDistance(
+	{latitude: 51.5103, longitude: 7.49347},
+	{latitude: "51° 31' N", longitude: "7° 28' E"}
+);
+geolib.getDistance(
+	{latitude: 51.5103, longitude: 7.49347},
+	{latitude: "51° 31' N", longitude: "7° 28' E"}
+);

// Working with W3C Geolocation API
-navigator.geolocation.getCurrentPosition(function(position) {
-	alert('You are ' + geolib.getDistance(position.coords, {latitude: 51.525, longitude: 7.4575}) + ' meters away from 51.525, 7.4575');
-}, function() { alert('Position could not be determined.'), {enableHighAccuracy: true});
+navigator.geolocation.getCurrentPosition(
+	function(position) {
+		alert('You are ' + geolib.getDistance(position.coords, {
+			latitude: 51.525,
+			longitude: 7.4575
+		}) + ' meters away from 51.525, 7.4575');
+	},
+	function() {
+		alert('Position could not be determined.')
+	},
+	{
+		enableHighAccuracy: true
+	}
+);
-### getCenter(array coords) +### geolib.getCenter(array coords) Calculates the geographical center of all points in a collection of geo coordinates @@ -54,7 +71,7 @@ geolib.getCenter([ ]);
-### isPointInside(object latlng, array coords) +### geolib.isPointInside(object latlng, array coords) Checks whether a point is inside of a polygon or not. Note: the polygon coords must be in correct order! @@ -74,7 +91,7 @@ geolib.isPointInside( ] ); // -> true -

isPointInCircle(object latlng, object center, integer radius)

+

geolib.isPointInCircle(object latlng, object center, integer radius)

Similar to is point inside: checks whether a point is inside of a circle or not. @@ -83,9 +100,13 @@ Returns true or false

Example

// checks if 51.525, 7.4575 is within a radius of 5km from 51.5175, 7.4678
-geolib.isPointInCircle({latitude: 51.525, longitude: 7.4575}, {latitude: 51.5175, longitude: 7.4678}, 5000);
+geolib.isPointInCircle( + {latitude: 51.525, longitude: 7.4575}, + {latitude: 51.5175, longitude: 7.4678}, + 5000 +); -

orderByDistance(object latlng, mixed coords)

+

geolib.orderByDistance(object latlng, mixed coords)

Sorts an object or array of coords by distance from a reference coordinate @@ -109,7 +130,7 @@ geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, { }); -### findNearest(object latlng, mixed coords, int offset) +### geolib.findNearest(object latlng, mixed coords, int offset) Finds the nearest coordinate to a reference coordinate. @@ -129,7 +150,7 @@ Finds the nearest coordinate to a reference coordinate. geolib.findNearest(spots['Dortmund U-Tower'], spots, 1) -### getPathLength(mixed coords) +### geolib.getPathLength(mixed coords) Calculates the length of a collection of coordinates @@ -145,7 +166,7 @@ geolib.getPathLength([ {latitude: 51.503333, longitude: -0.119722} // London ]); // -> 945235 -### convertUnit(string unit, float distance, [int round]) +### geolib.convertUnit(string unit, float distance, [int round]) Converts a given distance (in meters) to another unit. @@ -171,15 +192,15 @@ Converts a given distance (in meters) to another unit. `geolib.convertUnit('km', 14213, 2) // -> 14,21` -### sexagesimal2decimal(string coord) +### geolib.sexagesimal2decimal(string coord) Converts a sexagesimal coordinate to decimal format #### Example `geolib.sexagesimal2decimal("51° 29' 46\" N")` -### decimal2sexagesimal(float coord) +### geolib.decimal2sexagesimal(float coord) Converts a decimal coordinate to sexagesimal format @@ -189,7 +210,7 @@ Converts a decimal coordinate to sexagesimal format `geolib.decimal2sexagesimal(51.49611111); // -> 51° 29' 46.00` -### useDecimal(mixed coordinate) +### geolib.useDecimal(mixed coordinate) Checks if a coordinate is already in decimal format and, if not, converts it to
 @@ -1,11 +1,11 @@ -/** +/*! geolib 1.2.5 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.3 +* @version 1.2.5 * @license LGPL **/
 @@ -5,7 +5,7 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: '', meta: { - banner: '/**\n'+ + banner: '/*! <%= pkg.name %> <%= pkg.version %> by <%= pkg.author.name %>\n'+ '* A small library to provide some basic geo functions like distance calculation,\n' + '* conversion of decimal coordinates to sexagesimal and vice versa, etc.\n' + '* WGS 84 (World Geodetic System 1984)\n' +
 @@ -33,6 +33,6 @@ "scripts": { "test": "grunt travis --verbose" }, - "version": "1.2.4", + "version": "1.2.5", "main": "./geolib" }