我正在我的 Rails 应用程序视图中显示 Google 地图,并将使用标记/覆盖.
I'm displaying a Google map in my Rails app's view and will be using a marker/overlay.
坐标数据将来自手机 (GPS) 并存储在我的 Rails 应用程序的数据库中.
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?
(例如:你将如何舍入 35.2827524, -120.6596156 ?)
(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)
或
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.
这篇关于舍入经纬度以在 Google 地图中显示大致位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)