在android中计算两个经纬度点之间的距离 [英] Calculating the distance between two latitude and longitude points in android

查看:88
本文介绍了在android中计算两个经纬度点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于其中一个纬度&经度点我在数据库中&另一个我想使用手机的当前位置

For one of the latitude & longitude points i have it in database & another one i want to use current position of the mobile

我应该使用以下哪一个::

  • 安卓位置提供者
  • Google API
  • 数学计算

注意:: 任何演示代码示例都会有用

note:: Any demo code sample will be useful

推荐答案

您可以使用内置算法:

Location locationA = new Location("point A");     
locationA.setLatitude(latA); 
locationA.setLongitude(lngA);
Location locationB = new Location("point B");
locationB.setLatitude(latB); 
LocationB.setLongitude(lngB);
distance = locationA.distanceTo(locationB) ;

更新:(我对此没有任何错误)

update: (I don't have any error with this)

LatLng latLngA = new LatLng(12.3456789,98.7654321);
LatLng latLngB = new LatLng(98.7654321,12.3456789);

Location locationA = new Location("point A");
locationA.setLatitude(latLngA.latitude);
locationA.setLongitude(latLngA.longitude);
Location locationB = new Location("point B");
locationB.setLatitude(latLngB.latitude);
locationB.setLongitude(latLngB.longitude);

double distance = locationA.distanceTo(locationB);

这篇关于在android中计算两个经纬度点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆