如何获取当前精确的GPS坐标使用GPS_PROVIDER android系统中? [英] How to get the current accurate GPS Coordinates using GPS_PROVIDER in android?

查看:439
本文介绍了如何获取当前精确的GPS坐标使用GPS_PROVIDER android系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于GPS定位导航,用以查找用户当前位置的一个Android应用程序。我使用GPS_PROVIDER我不希望使用任何其他供应商一样PASSIVE_PROVIDER或NETWORK_PROVIDER目前我的code的工作,它给我的坐标准确,但是当我从应用程序退出,然后重新启动应用程序它给了我从略有不同的坐标而我在同一地点,同一位置旧的。
为了找到GPS坐标我用下面的code。

I am developing an android app based on GPS location navigation for finding user current location. I am using GPS_PROVIDER I dont want to use any other provider like PASSIVE_PROVIDER or NETWORK_PROVIDER currently my code is working and it gives me the coordinates accurately but when I exit from application and again start the application it gives me slightly different coordinates from the old ones while I am on same place and same position.
To find GPS coordinates I used following code.

LocationManager mlocManager = (LocationManager) 
        getSystemService(Context.LOCATION_SERVICE);
MyLocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
            0, mlocListener);

和我的监听器类

public class MyLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location loc) {
        loc.getLatitude();
        loc.getLongitude();
        String Text = "My current location is: " + "Latitud = "
            + loc.getLatitude() + "Longitud = " + loc.getLongitude();
        TextView txtgps = (TextView) findViewById(R.id.text_GPS_Coordinates);
        txtgps.setText(Text);
        Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
                .show();
    }

    @Override
    public void onProviderDisabled(String provider) {
        Toast.makeText(getApplicationContext(), "Disable",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onProviderEnabled(String provider) {
        Toast.makeText(getApplicationContext(), "Enable",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
}

我定义AndroidManifest权限是:

I define permission in AndroidManifest is :

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

请告诉我,让我准确而可靠的坐标,如果可能的方法,请解释一下你的code。

Please tell me the method which gives me the accurate and reliable coordinates and if possible, please explain your code.

推荐答案

您可能会想到的是,最近的位置锁定是最准确的。但是,由于位置坐标的精度变化,最新的修补并不总是最好的。您应该包括逻辑选择基于几个标准位置锁定。该标准还根据使用的用例的应用程序和现场测试的

You might expect that the most recent location fix is the most accurate. However, because the accuracy of a location fix varies, the most recent fix is not always the best. You should include logic for choosing location fixes based on several criteria. The criteria also varies depending on the use-cases of the application and field testing.

下面是一些可以采取的步骤来验证位置坐标的精度:

Here are a few steps you can take to validate the accuracy of a location fix:

  • 检查检索到的位置比previous估计显著更新。
  • 检查是否按要求的位置精度小于previous估计是好还是坏。
  • 检查其提供新的位置距离并决定是否需要更多的信任它。

除此之外,您的GPS可能会给你无论是WiFi或塔的最后一个缓存的位置。这是一个已知的bug,并克服这一点,你可以写你的自定义算法中忽略这一点。

Apart from this, your GPS might give you last cached location of either wifi or tower . This is a known bug and to overcome this, you can write your custom algo to ignore this.

这篇关于如何获取当前精确的GPS坐标使用GPS_PROVIDER android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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