Live data from Hacker News

How to generate random geo-coordinates within a given radius

jordinl.com

31–40 of 57 posts

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

#31

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…

Yeah, and it doesn't even need to be within a certain radius - just make it within a certain latitude / longitude.

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

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

On 2. the consequences can be real, as in the article linked below where people keep accusing a couple of stealing their phones. I believe in that case their house was located at the centroid of a zipcode and whatever tool was used to map it simply put a pin at the centroid. This suggests that just lowering accuracy is not sufficient to protect innocent parties if that lowered accuracy isn't reflected in the visualization, and an approach like highlighting a region is probably a better way to go than giving a precise but inaccurate location.

https://www.washingtonpost.com/news/the-switch/wp/2016/01/26...

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

#33

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…

Seems like another option is to generate points inside a bounding square and throw them away if they are outside of the circle.

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

#34
Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinates. I'm not sure if I'm missing something or if this is overengineered.

If people are interested I've included a link on how Tinder keeps your location private. It's really interesting.

https://robertheaton.com/2018/07/09/how-tinder-keeps-your-lo...

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

#35
post #34

Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinates. I'm not sure if I'm missing something or if this is overengineered. If people are interested I've included a link on how Tinder keeps your location private. It's really interesting. https://robertheaton.com/2018/07/09/how-tinder-keeps-your-lo...

That might work if you then apply a translation to the center point in pixel-space. But what if you need to send latitude and longitude to your front-end, or other display system? How do you translate your 2d polar coordinates to a change in spherical polar coordinates (lat+lon)? For small distances near the equator, it may not matter. Otherwise, it might.

The article could have helped answer your question by providing some images to illustrate the flaws with other solutions that the author tried.

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

#36
post #34

Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinates. I'm not sure if I'm missing something or if this is overengineered. If people are interested I've included a link on how Tinder keeps your location private. It's really interesting. https://robertheaton.com/2018/07/09/how-tinder-keeps-your-lo...

That doesn't create a uniform distribution over a disk. Heres a quick image (https://imgur.com/a/xHEpVB9) I generated using that method.

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

#37
post #34

Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinates. I'm not sure if I'm missing something or if this is overengineered. If people are interested I've included a link on how Tinder keeps your location private. It's really interesting. https://robertheaton.com/2018/07/09/how-tinder-keeps-your-lo...

This will give you a random distribution, but not a uniform one. Concrete description why: you're just as likely to end up 3 units from the center as 6 units from the center. However, there is twice as much space that is 6 units from the center than 3 units from the center.

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

#38

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…

>calculate points on a circle

This is a bad idea. If you don't randomly distribute points within the entire radius then you've just narrowed the search space for the real location from the entire area in the radius to just a circle around the point you give back.

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

#39
post #34

Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinates. I'm not sure if I'm missing something or if this is overengineered. If people are interested I've included a link on how Tinder keeps your location private. It's really interesting. https://robertheaton.com/2018/07/09/how-tinder-keeps-your-lo...

This will give you a random distribution, but not a uniform one. Concrete description why: you're just as likely to end up 3 units from the center as 6 units from the center. However, there is twice as much space that is 6 units from the center than 3 units from the center.

Thanks, makes perfect sense and should have been obvious.

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

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

> 1. How do you stop someone from finding the actual property location by querying that map a bunch of times and averaging the positions returned?

Back when YikYak was a thing, I was scraping the data for university campus through their API and found that their location data was randomized upon access. This meant that popular posts (they survived for longer) would end up producing pretty accurate location data.

In one case, I confirmed this by walking into the computer lab in the building where the Geography courses were located and asked "who was asking for lab help on YikYak?" and one student sheepishly raised his hand. I helped him and then also gave him a lesson on real world applications of the central limit theorem.

Post reply on HN