I'm displaying a Google map in my Rails app's view and will be using a marker/overlay.
The coordinate data will be coming from a phone (GPS) and stored in my Rails app's db.
The problem is, I don't want the precise lat/long visible in the source of my web page ... i.e. I want to mark an approximate location without giving away the true lat/long.
How can I round/truncate the lat/long values so they are still accurate (say, within a mile)–but not too accurate?
(Example: how would you round 35.2827524, -120.6596156 ?)
The easiest thing to do would be either to round both coordinates to a certain number of decimal places, or add a random dither to the coordinates:
lat = Math.floor(lat*1000+0.5)/1000; (round within 0.001)
or
dither=0.001;
lat = lat + (Math.random()-0.5)*dither;
If you really want to be within a certain number of miles, you'd need to do more-complex math, probably using polar coordinates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With