/** | |
* 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 generateRandomPoints(center, radius, count) { | |
var points = []; | |
for (var i=0; i<count; i++) { | |
points.push(generateRandomPoint(center, radius)); | |
} | |
return points; | |
} | |
/** | |
* 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 lat and lng attributes. | |
* @param {number} radius Radius in meters. | |
* @return {Object} The generated random points as JS object with lat and lng attributes. | |
*/ | |
function generateRandomPoint(center, radius) { | |
var x0 = center.lng; | |
var y0 = center.lat; | |
// Convert Radius from meters to degrees. | |
var rd = radius/111300; | |
var u = Math.random(); | |
var v = Math.random(); | |
var w = rd * Math.sqrt(u); | |
var t = 2 * Math.PI * v; | |
var x = w * Math.cos(t); | |
var y = w * Math.sin(t); | |
var xp = x/Math.cos(y0); | |
// Resulting point. | |
return {'lat': y+y0, 'lng': xp+x0}; | |
} | |
// Usage Example. | |
// Generates 100 points that is in a 1km radius from the given lat and lng point. | |
var randomGeoPoints = generateRandomPoints({'lat':24.23, 'lng':23.12}, 1000, 100); |
nice function to use in my situation with Cesiumjs to create random clouds with billboard. I tried to use a webservice which called a function in PostGIS to create random points on a geometry based on lat lon. But this is much more easy, so I will try this.
Awesome! Thank you! :) Needed 1 min and simple solution for dummy data, and here is your gist.
Awesome, thank you a lot!!! =]
Thank you a lot for saving my time. Cheers :)
It was very helpfull, thank you very much. God bless you !
it was very helpful thanks a lot
Thanks a lot, mister :) Surely you'll be credited on my project ...
Great stuff
helpful
Thank you!
Thanks
Thanks!
AWESSSSSSOME! Works like a charm.
Thanks for this. Using this to generate dummy data to simulate Covid-19 tracking data.
Thanks!
Very helpful. Thanks for posting this super useful function!
Hello, this was critically helpful, man! This is exactly what I needed! I re-implemented it in Python and it works like charm! Thank you again!
Thanks for this elegant utility. It is of great help for me...
thanks man its working good
in the open source days, a Star is a 'thanks'.
Thanks for make our life easier
Thanks alot. <3
Very nice thank you very much!
Thank you
thanks!
This is exactly what I need, thank you for the sharing!
Thank you
5 years ago, 32 starts and 0 thanks.
I guess this is not what most people think of when they publicly disclose their code snippets and projects, but alas, such is the reality.
I am here, writing this post, only to let you know that I am thankful for your decision to share it.
We were supposed to launch a product a couple of days ago, and since that didn't happen everything is on fire as you can imagine - including me.
I could have wasted precious time and created something like this, but the truth is I just don't have the time, I need help.
You helped me
I want to thank you for publicly sharing this. I want to thank you for commenting your code as well.
Now you don't have 32 stars and 0 thanks. You have 33 and 1 thanks. I guess you were expecting more, but this is all I can give. Hope its enough :P