1
votes

Title says it all, I need to scramble lat/lon coordinates within 100m radius for privacy reasons. I'm just horrible at maths and can't figure out how to convert 100m to lat/lon...

Eg I would have a location like:

lat: 52.5037086
lng: 13.434223100000054

Need to scramble this within 100m radius randomly, ie the furthest the generated coordinates can be from the original coordinates in any direction is 100m.

I've seen this formula around:

d = acos( sin1)⋅sin2) + cos1)⋅cos2)⋅cos(Δλ) ) ⋅ R

where:  
    φ = latitude, λ = longitude
    R = radius of earth
    d = distance between the points

No idea how to accomplish this in JavaScript, though. These "points" are markers within a Google Map if it makes a difference.

To be honest, it doesn't even need to be a circle, just random location within 100m x 100m square would work as well.

1
So basically you need a 100 meter radius circular area whose center should be ( 52.5037086, 13.434223100000054) right ?Banik
Yes, and then somehow use math.random to pick a point within that radius.j_d

1 Answers

0
votes

At such small extents, we can work with a linear approximation of the problem and a spherical earth model.

Consider, you are at a position (lat, long). Then, increasing lat by 1° results in a distance from the original point of d_lat = Pi * R * 1°/180° (simple perimeter of a circle).

Similarly, increasing long by 1° results in a distance of d_long = cos(lat) * Pi * R * 1°/180°.

Then, you can calculate the maximum change of latitude and longitude:

maxChangeLatitude  = 100 m / d_lat
maxChangeLongitude = 100 m / d_long

Find a random point in this square and you have your point:

newLat  = lat  + (2 * Math.random() - 1) * maxChangeLatitude;
newLong = long + (2 * Math.random() - 1) * maxChangeLongitude;