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
ParameterDescription
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
ParameterDescription
deg *
Type: Number
Degrees to convert.

Returns: deg converted to radians.

1const advancedMath = require('advanced_math');
2const radians = advancedMath.deg2rad(30);

Was this page useful?

Last updated on