Live data from Hacker News

How to generate random geo-coordinates within a given radius

jordinl.com

21–30 of 57 posts

Re: How to generate random geo-coordinates within a given radius

#21

Over engineered much? > On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location. At those distances, you can treat the surface as a plane and calculate points…

I wrote an app where we needed to get a list of properties within a radius of a given property, using lat/long coordinates. Given the search radius would be at most 5 miles, and didn't need to be 100% precise, I just treated the surface as a plane. A trivial solution to a trivial problem-- but it is neat to know the details of the formula for doing it precisely should I ever need it.

Re: How to generate random geo-coordinates within a given radius

#22
post #8

Earlier quoted context omitted.

I imagine its for something like AirBnb where the site doesn't want the users to the location the property so they only way to book it is via the site.

What's funny with Airbnb is that if you are looking at the map in search, it is approximate. However, if you save the property to your favorites and then go to your favorite list and look at the map, you get the exact location.

Could not reproduce. I tested with different properties and while it shows as an exact location in the map, it is still being fuzzed.

Re: How to generate random geo-coordinates within a given radius

#24
post #19
post #7

> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location This raises a couple of interesting questions. 1. How do you stop someone from finding the actual pr…

We used a slightly modified version of the code in the article. Instead of using random numbers we used pseudo-random numbers so the positions didn't change across requests.

Is the pseudo-random number generator cryptographically secure?

Re: How to generate random geo-coordinates within a given radius

#25
post #7

> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location This raises a couple of interesting questions. 1. How do you stop someone from finding the actual pr…

> 2. Are there any negative consequences for the people whose property a displaced marker ends up on?

That's definitely plausible: https://splinternews.com/how-an-internet-mapping-glitch-turn...

Re: How to generate random geo-coordinates within a given radius

#26
post #7

> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location This raises a couple of interesting questions. 1. How do you stop someone from finding the actual pr…

https://gizmodo.com/how-cartographers-for-the-u-s-military-i...

https://splinternews.com/how-an-internet-mapping-glitch-turn...

In those cases there were negative consequences because low-precision markers were not displaced.

Re: How to generate random geo-coordinates within a given radius

#27
post #24
post #19

Earlier quoted context omitted.

We used a slightly modified version of the code in the article. Instead of using random numbers we used pseudo-random numbers so the positions didn't change across requests.

Is the pseudo-random number generator cryptographically secure?

Every set of coordinates uses a different seed, so I would say yes.

Re: How to generate random geo-coordinates within a given radius

#30

Over engineered much? > On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location. At those distances, you can treat the surface as a plane and calculate points…

I was thinking the same thing. Just generate two random numbers in polar coordinates and then map back to a cartesian offset. Only trickiness is taking the square root of one of the numbers to generate the radius rather than the random number itself.
Post reply on HN