TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to generate random geo-coordinates within a given radius

94 pointsby jordinlover 6 years ago

11 comments

tzsover 6 years ago
&gt; 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<p>This raises a couple of interesting questions.<p>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?<p>2. Are there any negative consequences for the people whose property a displaced marker ends up on? For example, if someone is using the map lookup to find the home of a rival gang officer in order to do a drive by attack, and I happen to live down the street, I really don&#x27;t want that marker showing up on my house.<p>Rather than a displaced marker, maybe divide the map into rectangular or hexagonal regions, and just highlight the region containing the property.
评论 #19195888 未加载
评论 #19193272 未加载
评论 #19195964 未加载
评论 #19193131 未加载
评论 #19192449 未加载
评论 #19194035 未加载
评论 #19193297 未加载
评论 #19192387 未加载
评论 #19192964 未加载
usrusrover 6 years ago
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.<p>If for some reason the data needs to appear random, you have to store a fixed random offset&#x2F;alternative per point so that there cannot be multiple observations.<p>If for some reason the data needs to appear randomized between repeated lookups, you need to store a fixed offset&#x2F;alternative per point and then apply an additional random offset per lookup. Repeated lookups will only leak the (badly) hidden permanently randomized stored alternative.
评论 #19196262 未加载
femto113over 6 years ago
If the rationale is privacy this is probably not the algorithm you want to use, especially if it&#x27;s possible to force the generation of multiple random points (e.g. by refreshing the map). If you&#x27;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 precision.
评论 #19192502 未加载
评论 #19193140 未加载
评论 #19192368 未加载
mtmailover 6 years ago
I regularly use this tool (nodejs) for a list of random coordinates inside a country. Or at least inside any country to avoid the oceans. <a href="https:&#x2F;&#x2F;github.com&#x2F;tsamaya&#x2F;random-points-generator" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tsamaya&#x2F;random-points-generator</a>
MRD85over 6 years ago
Why can&#x27;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&#x27;ve got polar coordinates. I&#x27;m not sure if I&#x27;m missing something or if this is overengineered.<p>If people are interested I&#x27;ve included a link on how Tinder keeps your location private. It&#x27;s really interesting.<p><a href="https:&#x2F;&#x2F;robertheaton.com&#x2F;2018&#x2F;07&#x2F;09&#x2F;how-tinder-keeps-your-location-a-bit-private&#x2F;" rel="nofollow">https:&#x2F;&#x2F;robertheaton.com&#x2F;2018&#x2F;07&#x2F;09&#x2F;how-tinder-keeps-your-lo...</a>
评论 #19195762 未加载
评论 #19194856 未加载
评论 #19196168 未加载
评论 #19195727 未加载
chad_thunderover 6 years ago
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.
评论 #19192541 未加载
评论 #19192171 未加载
unterbahnover 6 years ago
Leaflet.BlurredLocation <a href="https:&#x2F;&#x2F;github.com&#x2F;publiclab&#x2F;leaflet-blurred-location" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;publiclab&#x2F;leaflet-blurred-location</a> - A Leaflet-based HTML interface for selecting a &quot;blurred&quot; or low-resolution location, to preserve privacy.<p>H3 is similar and cool, but this builds a similar nested grid concept around latitude&#x2F;longitude, which can map to existing coordinate systems and database storage.<p>Also note that population density affects how effective a given precision &quot;blur&quot; is for an area; we&#x27;re also hoping to develop a web service or library to roughly return population density for any given region of the globe.
评论 #19196321 未加载
jimsmartover 6 years ago
Converting lat&#x2F;longs to Uber&#x27;s H3 [1][2] system might prove useful here. Because H3 indexes are hierarchical, you can easily truncate them to obtain less precision. And then convert them back into lat&#x2F;longs after truncation.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;uber&#x2F;h3" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;uber&#x2F;h3</a><p>[2] <a href="https:&#x2F;&#x2F;eng.uber.com&#x2F;h3&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eng.uber.com&#x2F;h3&#x2F;</a>
GhostVIIover 6 years ago
In practice, would it be easier to just randomly generate points within the bounding box of the radius, and then throw out any points that fall outside of the circle? Wouldn&#x27;t work too well for the cases where you want points from some radius away, to some radius away, but would probably work well when you just want a random point inside of a given radius since only 1&#x2F;4 of the points will have to be thrown out.
评论 #19196624 未加载
dangover 6 years ago
This is a fine submission but can you please not put &quot;Show HN&quot; on blog posts? This is in the rules: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;showhn.html" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;showhn.html</a>.
评论 #19193374 未加载
iknowordidthatover 6 years ago
Over engineered much?<p>&gt; 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.<p>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.
评论 #19194138 未加载
评论 #19193655 未加载
评论 #19193622 未加载
评论 #19193178 未加载
评论 #19195856 未加载