JSFiddle - React, Tailwind, and code Playground

by ABBEYSOFT

HTML

k

JavaScript

/**
* 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.1.8
* @license LGPL 
**/

(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 googleClientId;
	var googlePrivateKey;
	if (typeof window.navigator === 'undefined') {
		var gm = require('googlemaps');
	}

	var geolib = {
		distanceFormula: 'haversine',

		decimal: {},

		sexagesimal: {},

		distance: 0,

		/**
		* Get the key names for a geo point.
		*
		* @param	object	Point position {latitude: 123, longitude: 123, elevation: 123}
		* @return	object	{
		*						longitude: 'lng|long|longitude',
		*						latitude: 'lat|latitude',
		*						elevation: 'alt|altitude|elev|elevation' 
		*					}
		*/
		getKeys: function(point) {
			var latitude = point.hasOwnProperty('lat') ? 'lat' : 'latitude';
			var longitude = (point.hasOwnProperty('lng') ? 'lng' : false) ||
											(point.hasOwnProperty('long') ? 'long' : false) ||
											'longitude';
			var elevation = (point.hasOwnProperty('alt') ? 'alt' : false) ||
											(point.hasOwnProperty('altitude') ? 'altitude' : false) ||
											(point.hasOwnProperty('elev') ? 'elev' : false) ||
											'elevation';
			return {
				latitude: latitude,
				longitude: longitude,
				elevation: elevation
			};
		},

		setDistanceFormula: function(formula) {
			formula = formula ? formula.toLowerCase() : 'vincenty';
			geolib.distanceFormula = formula;
		},

		/**
		* Calculates geodetic distance between two points specified by latitude/longitude using 
		* haversine by default, but can be changed in config
		*
		* @param    object    Start position {latitude: 123, longitude: 123}
		* @param    object    End position {latitude: 123,...