Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generate-random-points

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-random-points

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?

  • 0.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 04 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc