android - 使用谷歌地图和用户定义函数时获得不同的距离

标签 android

我想获得两个纬度和经度之间的距离,以米/公里为单位。所以我正在使用以下功能。它给我的结果与谷歌地图不同。

你能帮我解决我的问题吗?我不明白这是什么问题?

代码

   float[] results = {0};

   android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, results);

当前纬度 = 23.012281666666663 当前经度 = 72.51798333333333

目的地纬度 = 23.1120487 目的地纬度= 72.5766759

它以米为单位给出这个结果 = 12579.679,而在谷歌地图中它给出这个结果 = 17.9 公里

我不明白为什么这两个给出不同的结果。

最佳答案

这个图表解释了为什么你得到 12.5 和 17.6 公里


enter image description here


要计算行驶距离(17.6 公里),您需要使用 directions API

关于android - 使用谷歌地图和用户定义函数时获得不同的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7696112/

相关文章:

android - 如何获取启用 GPS 的手机的摄像头方向?

android - “ Material ”与 'MaterialComponents'

android - 使用 Mono for Android 以编程方式/动态添加按钮控件以查看{示例}

android - 将服务部署到 Google Play

java - 在 Android 浏览器缓存中注入(inject)项目

android - 带日期的语音识别

android - android中的动画轮效果

android - 当设备上有相同的 native (Apple/Google) 帐户但应用程序帐户不同时恢复应用内购买

android - 移动必需品的 Web 服务

android - 使用 Dagger 将 android.content.Context 注入(inject)构造函数