diff options
| author | Vivek Seth <[email protected]> | 2016-05-06 01:58:48 -0400 |
|---|---|---|
| committer | Vivek Seth <[email protected]> | 2016-05-06 01:58:48 -0400 |
| commit | 08e264b10ffceaf7a389753f56331d09a68eafe2 (patch) | |
| tree | 5d4985fc82b59d121904911c4e9b69999aebebc9 /lib/address.js | |
| parent | 0bfeb93c594ef31d4002eac6356a81b9e19fbb80 (diff) | |
| download | faker-08e264b10ffceaf7a389753f56331d09a68eafe2.tar.xz faker-08e264b10ffceaf7a389753f56331d09a68eafe2.zip | |
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.
Diffstat (limited to 'lib/address.js')
| -rw-r--r-- | lib/address.js | 14 |
1 files 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)]; } }; |
