From 08e264b10ffceaf7a389753f56331d09a68eafe2 Mon Sep 17 00:00:00 2001 From: Vivek Seth Date: Fri, 6 May 2016 01:58:48 -0400 Subject: Using different heuristic for producing a random GPS coordinate this approach will not result in a uniform distribution, but will instead concentrate points in the center. --- lib/address.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/address.js b/lib/address.js index f6e5be12..dde53b0d 100644 --- a/lib/address.js +++ b/lib/address.js @@ -116,7 +116,7 @@ var address = { function kilometersToMiles(miles) { return miles * 0.621371; } - function boundaryCoordinate(coordinate, bearing, distance, isMetric) { + function coordinateWithOffset(coordinate, bearing, distance, isMetric) { var R = 6378.137; // Radius of the Earth (http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html) var d = isMetric ? distance : kilometersToMiles(distance); // Distance in km @@ -147,14 +147,12 @@ var address = { radius = radius || 10.0; isMetric = isMetric || false; - // This is a heuristic to approximate the circular region defined by coordinate and radius. - topLeftBoundary = boundaryCoordinate(coordinate, degreesToRadians(45), radius, isMetric); - bottomRightBoundary = boundaryCoordinate(coordinate, degreesToRadians(45), -radius, isMetric); + // TODO: implement either a gaussian/uniform distribution of points in cicular region. + // Possibly include param to function that allows user to choose between distributions. - randLat = randomFloat(topLeftBoundary[0], bottomRightBoundary[0]).toFixed(4); - randLong = randomFloat(topLeftBoundary[1], bottomRightBoundary[1]).toFixed(4); - - return [randLat, randLong]; + // This approach will likely result in a higher density of points near the center. + var randomCoord = coordinateWithOffset(coordinate, degreesToRadians(Math.random() * 360.0), radius, isMetric); + return [randomCoord[0].toFixed(4), randomCoord[1].toFixed(4)]; } }; -- cgit v1.2.3