0.0.0 • Published 7 years ago

generate-random-points v0.0.0

Weekly downloads
45
License
MIT
Repository
github
Last release
7 years ago

generateRandomPoints(center, radius, count)

semantic-release js-standard-style Commitizen friendly

Dependency Status devDependency Status

Build Status Coverage Status

Generates random geolocation objects, in the form of plain-old javascript objects.

Usage

Install it with npm or yarn and use as a normal module

Installing

$ npm install generate-random-points --save

Consider this code:

'use strict'

const {
  generateRandomPoint,
  generateRandomPoints
} = require('generate-random-points')

const options = {
  centerPosition: {
    lat: 24.23,
    lng: 23.12
  },
  radius: 1000,
  count: 2
}

let listOfPoints = generateRandomPoints(options.centerPosition, options.radius, options.count)
let singlePoint = generateRandomPoint(options.centerPosition, options.radius)

return {
  listOfPoints,
  singlePoint
}

It should produce something like this:

{
  "listOfPoints": [
    {
      "latitude": 24.229716908541928,
      "longitude": 23.11553173995286
    },
    {
      "latitude": 24.234458720495013,
      "longitude": 23.10966586687313
    }
  ],
  "singlePoint": {
    "latitude": 24.232510757349,
    "longitude": 23.12242028161285
  }
}

API

function generateRandomPoints (center, radius, count)

/**
 * Generates number of random geolocation points given a center and a radius.
 *
 * @param  {Object} center A JS object with lat and lng attributes.
 * @param  {number} radius Radius in meters.
 * @param  {number} count Number of points to generate.
 * @return {array} Array of Objects with lat and lng attributes.
 */

function generateRandomPoint (center, radius)

/**
 * Generates number of random geolocation points given a center and a radius.
 *
 * Reference URL: http://goo.gl/KWcPE.
 * @param  {Object} center A JS object with 'latitude' and 'longitude' attributes.
 * @param  {number} radius Radius in meters.
 * @return {Object} The generated random points as JS object with latitude and longitude attributes.
 */

Credits

All those involved in this stackoverflow page: http://goo.gl/KWcPE @mkhatib for publishing this snippet of code in this gist https://gist.github.com/mkhatib/5641004