Geolib.js
I created a small JavaScript library to provide some basic geo functions like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc.
Usage:
To calculate distance between two geo coordinates
geolib.getDistance({"latitude": 51.511928, "longitude": 7.463536}, {"latitude": 51.510318, "longitude": 7.524133}, 10); // -> 4200 (Accuracy 10m)
Takes 2 or 3. First 2 arguments must be an object with a latitude and a longitude property (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.
Return value is always an integer and represents the distance in meters.
To convert it into miles use:
geolib.convertUnit('mi', value)
Convert sexagesimal to decimal
geolib.sexagesimal2decimal("51° 29' 46\" N"); // -> 51.49611111
Convert decimal to sexagesimal
geolib.decimal2sexagesimal(51.49611111); // -> 51° 29' 46.00
Download:
https://github.com/manuelbieh/geolib
Demo:
http://www.manuel-bieh.de/publikationen/scripts/geolib/demo.html
Veröffentlicht: 6.08.2011, 12:45 Uhr
Rubrik:
Tags: Geo, Geolocation, Javascript
Diskussion: 4 Kommentare