将位置放在用户周围一定半径的地图上 - android
我正在开发一个 GPS 应用程序,并且正在考虑在用户周围放置标记的想法,如 僵尸奔跑 和SpecTrek 但我完全不知道如何找出用户周围的位置。
我一直在查看 Location 类的文档,并使用 distanceTo() 函数来处理其他事情,以及 MapView 的 latitudeSpan()、longitudeSpan() 和 getProjection() 函数,但我不知道如何决定例如,用户周围 100 米。
因为我知道用户的位置,并且我只会放置距离用户最多 1 公里的标记,我可以将该区域视为平坦的而不是椭圆形的,这样就可以获取用户的经度和纬度+/- 从它们周围绘制一个标记(使用一些基本的三角函数,例如 x = cos(radius) 和 y = sin(radius) 将其保持在玩家周围半径大小的圆圈内)?
我不明白长度/纬度对应于实际标量距离,因为 100long 100lat 与 90long 100lat 相距 10 米吗? (我知道这些值是完全错误的,但只是用它们来说明我的问题)。
感谢您抽出时间,
Infinitifizz
I am working on a GPS application and was toying with the idea of putting markers around the user like in Zombie Run and SpecTrek but am completely confused about how to find out the locations around the user.
I have been looking at the documentation for the Location class and have used the distanceTo() function for other things as well as MapView's latitudeSpan(), longitudeSpan() and getProjection() functions but I can't think how to decide on locations that are, for example, 100 metres around the user.
As I know the users position and I am only going to be placing markers that are ~1km away from the user, at the most, can I treat the area as flat rather than ellipsoidal and so then just could take the user's longitude and latitude and +/- from them to plot a marker around them (using some basic trigonometry such as x = cos(radius) and y = sin(radius) to keep it within the radius-sized circle around the player)?
I don't understand how long/lat correspond to actual scalar distances as in would 100long 100lat be 10 metres away from 90long 100lat? (I know these values are completely wrong but just using them to illustrate my question).
Thanks for your time,
Infinitifizz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个经度/纬度点之间的距离通过半正矢公式计算。这是理论的链接:
http://www.movable-type.co.uk/scripts/latlong.html
我会使用您已经提到的 distanceTo 方法来实现您的目的。您拥有当前位置和所有兴趣点。只需为每个兴趣点调用 Location.distanceTo(Poi) 即可,如果距离大于 1000 米,您可以将该点绘制到地图上。
如果您没有 PoIs 作为位置对象,只需像这样构建它们:
我在类似雷达的应用程序中使用了 distanceTo 方法,并且工作得很好。
The distance between two longitude/latitude points is calculated with the haversine formula. Here is a link with the theoretics:
http://www.movable-type.co.uk/scripts/latlong.html
I would use the distanceTo method which you already mentioned for your purpose. You have your current Location and all your Points of Interest. Just call Location.distanceTo(Poi) for each Point of Interest and if the distance is larger than 1000 meters you can draw the point to your map.
If you don't have your PoIs as Location objects just build them like this:
I used the distanceTo method in a radar like app and worked just fine.
在靠近页面底部的地方,公式的描述更好一些。在那里你可以看到他在计算之前转换为弧度。此外,使用正确的数据类型以避免数字的错误舍入也至关重要。这是一个应该可以工作的小代码片段:
A little closer to the bottom of the page the formular is described a little bit better. There you can see that he converted to radians before calculating. Also it is crucial that you use the right datatypes to avoid false rounding of numbers. Here is a small code snippet which should work: