【发布时间】:2014-02-25 09:44:13
【问题描述】:
我认为这个问题众所周知。
那么我的问题是什么?
我正在编写一个应用程序,它使用 GPS 提供程序来查找用户的位置并计算从用户到终点的距离。这可以正常工作。但是出现了问题:
问题详情:
如果您使用我的应用程序在城市中转转,它会为您提供一些距离数字,但是......距离正在改变。无论我是否朝着目的地移动,距离要么变高要么变低(计算的距离值是从高到低“跳跃”,反之亦然)之前的距离数字,但从逻辑上讲它应该越来越低.我相信这是因为 GPS 信号有时会丢失或微弱,无法正确计算距离。
我需要什么帮助?
我想知道有没有办法过滤从 GPS 接收到的坐标,这样我就可以获得更准确的距离数字,所以当我向终点移动时,距离计算正确(尽可能不必是 100%正确),而不是像疯了似的上下秤。
如何获取坐标并计算距离:
public void onLocationChanged(Location location)
{
txtLat = (TextView) findViewById(R.id.currentCoordinatesView);
clat = location.getLatitude();
clong = location.getLongitude();
Location location1 = new Location("Start");
location1.setLatitude(clat);
location1.setLongitude(clong);
Location locationB = new Location("Finish");
locationB.setLatitude(endLatitude); //endpoint coordinates
locationB.setLongitude(endLongitude);
distance = location1.distanceTo(locationB); //calculate the distance
TextView TextDistance = (TextView)findViewById(R.id.TextDistance);
TextDistance.setText(new DecimalFormat("##,###,###.##").format(distance)+" m");
CurLat = location.getLatitude();
CurLong = location.getLongitude();
【问题讨论】:
-
你知道location对象有accuracy属性吧?
-
好吧,这是真的,但我不知道如何实现它,你能告诉我吗?
标签: android localization gps