aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVivek Seth <[email protected]>2016-05-06 01:58:21 -0400
committerVivek Seth <[email protected]>2016-05-06 01:58:21 -0400
commit0bfeb93c594ef31d4002eac6356a81b9e19fbb80 (patch)
tree3e4381dcac7835edd49470ac8df95d3c44909bb3 /lib
parent43495cc4c07061610d318eb2b31e6b7075810f33 (diff)
downloadfaker-0bfeb93c594ef31d4002eac6356a81b9e19fbb80.tar.xz
faker-0bfeb93c594ef31d4002eac6356a81b9e19fbb80.zip
Ensure longitude points are within range [-180, 180]
Diffstat (limited to 'lib')
-rw-r--r--lib/address.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/address.js b/lib/address.js
index 5fa924d4..f6e5be12 100644
--- a/lib/address.js
+++ b/lib/address.js
@@ -130,6 +130,13 @@ var address = {
Math.sin(bearing) * Math.sin(d/R) * Math.cos(lat1),
Math.cos(d/R) - Math.sin(lat1) * Math.sin(lat2));
+ // Keep longitude in range [-180, 180]
+ if (lon2 > degreesToRadians(180)) {
+ lon2 = lon2 - degreesToRadians(360);
+ } else if (lon2 < degreesToRadians(-180)) {
+ lon2 = lon2 + degreesToRadians(360);
+ }
+
return [radiansToDegrees(lat2), radiansToDegrees(lon2)];
}