如何计算两个位置之间的距离并显示路线?

发布于 2024-11-09 10:38:09 字数 634 浏览 0 评论 0原文

我需要计算我的 Android 应用程序中两个位置之间的距离。然后我需要在地图上显示路线。

看来我需要使用一些 Google API 来计算距离。应该是 Google Directions API 吗? Android 文档我应该使用 Google Maps 外部库,但我不这样做没有看到有任何相同的方法。 也许,如果我只想计算两点之间的距离而不是步行距离,最好使用一些简化的方法。

然后显示地图 - 与在用户浏览器中根据 url 打开相比,使用 MapView 的优势是什么? 希望避免以下行为:

当你准备好释放你的 申请时,您必须注册您的 与Google发布证书 地图服务并获取新的地图 API 钥匙。然后您必须更改 MapView 您的应用程序中的元素 引用新的 API 密钥。

I need to calculate distance between two locations in my android application. Then I need to display the way on the map.

Looks like I need to use some Google API to calculate the distance. Should it be Google Directions API? Android documentation says that I should use Google Maps External Library, but I don't see there any method for the same.
Probably, if I want just to calculate the distance between two points and not walking distance better to use some simplified approach.

Then to display the map - what is the advantage of usage of MapView compared with opening according url in user's browser?
Would like to avoid the following actions:

When you are ready to release your
application, you must register your
release certificate with the Google
Maps service and obtain a new Maps API
Key. You must then change the MapView
elements in your application to
reference the new API key.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心作怪 2024-11-16 10:38:09

你也可以这样做:

//your two locations
Location locationA;
Location locationB;

//distance between them
float distanceBetweenPoints = locationA.distanceTo(locationB);

有点晚了,但希望这会有所帮助:)

You could also just do this:

//your two locations
Location locationA;
Location locationB;

//distance between them
float distanceBetweenPoints = locationA.distanceTo(locationB);

bit late but hopefully this helps :)

香草可樂 2024-11-16 10:38:09

可以使用此处描述的方程找到两点之间的距离:
http://williams.best.vwh.net/avform.htm#Dist
请记住,使用弧度,而不是角度!

您似乎担心在每个版本中更新地图密钥?我在市场上有一个基于地图的应用程序,您将获得 1 个产品密钥和 1 个调试密钥(我相信它是每个开发人员的,但如果不是,它是每个应用程序的)。它与您用来签署 apk 的密钥有关。我的意思是,如果您获得了 prod api 密钥,并且只开发了这个应用程序,您可以发布许多更新,而无需再次触摸该密钥(假设您不在本地进行调试密钥测试) 。如果您担心这一点,可以将两者都保留在 AndroidManifext.xml 文件中,并注释掉不相关的文件,具体取决于您是部署到设备还是模拟器。

The distance between two points can be found by using the equation described here:
http://williams.best.vwh.net/avform.htm#Dist
remember, use radians, not degrees!

It seems you have concern about updating a maps key in each release? I have an app in the market that is map-based, and you get 1 prod key and 1 debug key (I believe it's per developer, but if not, it's per app). It has to do with the key you use to sign your apk. What I'm saying is that if you get your prod api key, and only ever develop this one app, you can publish many many updates without ever having to touch the key again (assuming you don't do debug-key testing locally). If you're concerned about it, you can keep both in your AndroidManifext.xml file and just comment out the irrelevant one, depending on whether you're deploying to a device or emulator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文