舍入经纬度以在 Google 地图中显示大致位置

Rounding Lat and Long to Show Approximate Location in Google Maps(舍入经纬度以在 Google 地图中显示大致位置)
本文介绍了舍入经纬度以在 Google 地图中显示大致位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在我的 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 地图中显示大致位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)