advanced_math
The advanced_math built-in module is available only inside a PubNub Function. It calculates distances and converts degrees to radians.
1const advancedMath = require('advanced_math');
getDistance
getDistance(lat1, lon1, lat2, lon2)
* required
| Parameter | Description |
|---|---|
lat1 *Type: Number | Latitude of the first point. |
lon1 *Type: Number | Longitude of the first point. |
lat2 *Type: Number | Latitude of the second point. |
lon2 *Type: Number | Longitude of the second point. |
Returns: the distance between the two points, in miles.
1const advancedMath = require('advanced_math');
2const distanceInMiles = advancedMath.getDistance(43.70011, -79.4163, 37.77493, -122.41942);
deg2rad
deg2rad(deg)
* required
| Parameter | Description |
|---|---|
deg *Type: Number | Degrees to convert. |
Returns: deg converted to radians.
1const advancedMath = require('advanced_math');
2const radians = advancedMath.deg2rad(30);
Related reference
- Modules and libraries. Every built-in module available inside a Function.