【发布时间】:2017-05-29 06:08:53
【问题描述】:
我有一个关于位置的问题,我的程序将应用程序的位置保存到 firebase 数据库中,没关系,我需要将我的位置与数据库中的位置进行比较,我使用 userData 对象将坐标保存到其中:
Location dbLocation = new Location("dbLocation");
dbLocation.setLatitude(userData.lat);
dbLocation.setLongitude(userData.lng);
我从 GPSTracker 服务获取我的位置坐标:
Location crntLocation = new Location("crntLocation");
crntLocation.setLongitude(gpstracker.getLongitude());
crntLocation.setLatitude(gpstracker.getLatitude());
我需要比较这个坐标并找出两个位置之间的距离
float distanceBetween = crntLocation.distanceTo(dbLocation);
但它不起作用,我不知道为什么,请您帮忙解决它吗?
【问题讨论】:
-
你在
distanceBetween中得到什么价值? -
你试过
distanceBetween的方法吗? developer.android.com/reference/android/location/… -
你说它不起作用是什么意思?它会抛出异常吗?