Live data from Hacker News

How to generate random geo-coordinates within a given radius

jordinl.com

11–20 of 57 posts

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

#11
post #8
post #6

If the rationale is privacy this is probably not the algorithm you want to use, especially if it's possible to force the generation of multiple random points (e.g. by refreshing the map). If you're using a circle with a fixed radius just 3 points would be enough to exactly locate the center. A variable radius could take more, but since the distribution is uniform each additional point would significantly improve the…

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.

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

#12
post #6

If the rationale is privacy this is probably not the algorithm you want to use, especially if it's possible to force the generation of multiple random points (e.g. by refreshing the map). If you're using a circle with a fixed radius just 3 points would be enough to exactly locate the center. A variable radius could take more, but since the distribution is uniform each additional point would significantly improve the…

If you used a fingerprinting library as the seed for random, it would be repeatable per user.

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

#13
Any random distribution will be leaky when it is centered around the real location and multiple samples can be taken. Quantization to a desired lack of precision is the answer, nobody will be able to tell a point that happens to be rounded to itself from one that happens to be rounded from close to a neighboring cell.

If for some reason the data needs to appear random, you have to store a fixed random offset/alternative per point so that there cannot be multiple observations.

If for some reason the data needs to appear randomized between repeated lookups, you need to store a fixed offset/alternative per point and then apply an additional random offset per lookup. Repeated lookups will only leak the (badly) hidden permanently randomized stored alternative.

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

#15

Buffer your point to create a polygon then use ST_PointOnSurface (or equivalent) in any competent spatially-enabled DBMS to create a point guaranteed to intersect the bounding polygon. Trivial in SQLite, PostGIS, etc.

how is that generated point random in any way?

https://gis.stackexchange.com/questions/76498/how-is-st-poin...

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

#16
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 on a circle. Sure, it won’t be accurate for large distances but that is not a requirement. Nor is accuracy for that matter since the whole point is to obfuscate the original point.

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

#17
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…

Amusingly, this is the first time that I've seen the Law of Large Numbers being treated as a negative thing.

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

#18
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.

Some Airbnb engineer just got pinged...

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

#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.

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

#20
post #6

If the rationale is privacy this is probably not the algorithm you want to use, especially if it's possible to force the generation of multiple random points (e.g. by refreshing the map). If you're using a circle with a fixed radius just 3 points would be enough to exactly locate the center. A variable radius could take more, but since the distribution is uniform each additional point would significantly improve the…

As I mentioned in a different comment, 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.
Post reply on HN