0

我有下一个问题,我需要使用互联网获取坐标,但是当我连接到移动互联网(Edge)时,我在整个公寓中得到相同的坐标,当我使用 WI Fi 时坐标不同。我的代码是:

public class FetchCordinates extends AsyncTask<String, Integer, String> {
    ProgressDialog progDailog = null;

    public LocationManager mLocationManager;
    public VeggsterLocationListener mVeggsterLocationListener;

    @Override
    protected void onPreExecute() {
        mVeggsterLocationListener = new VeggsterLocationListener();
        mLocationManager = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);

        mLocationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, 1000, 10,
                mVeggsterLocationListener);

        progDailog = new ProgressDialog(getActivity());


        progDailog.setTitle("Получение координат");
        progDailog
                .setMessage("Получение Вашего местоположения, ожидайте, это может занять несколько минут...");
        progDailog.setIndeterminate(true);


        progDailog.setCancelable(false);
        progDailog.setButton(DialogInterface.BUTTON_NEGATIVE, "Отмена",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        FetchCordinates.this.cancel(true);
                        mLocationManager
                                .removeUpdates(mVeggsterLocationListener);
                    }
                });
        progDailog.show();

    }

    @Override
    protected void onCancelled() {
        Log.d("myLogs", "Cancelled by user!");
        progDailog.dismiss();

    }

    @Override
    protected void onPostExecute(String result) {
        progDailog.dismiss();
        if (myLat == 0) {
            new AlertDialog.Builder(getActivity())
                    .setTitle("Ошибка получения координат")
                    .setMessage("Попробуйте позже...")
                    .setPositiveButton("Ок",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    // continue with delete
                                }
                            }).show();

        } else {

            pg = new Progress();
            pg.execute("");
        }

    }

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        long timeOfStartingThread = System.currentTimeMillis();
        while (myLat == 0.0) {
            if (System.currentTimeMillis() - timeOfStartingThread > timeToGetGps_ms) {
                break;
            }
        }
        mLocationManager.removeUpdates(mVeggsterLocationListener);
        return null;
    }

    public class VeggsterLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {

            try {



                myLat = location.getLatitude();
                myLong = location.getLongitude();

                 Toast.makeText(
                 getActivity(),
                 " Координаты получены :" + myLat
                 + ", :" + myLong,
                 Toast.LENGTH_SHORT).show();

            } catch (Exception e) {

            }

        }

        @Override
        public void onProviderDisabled(String provider) {
            Log.d("myLogs", "OnProviderDisabled");
        }

        @Override
        public void onProviderEnabled(String provider) {
            Log.d("myLogs", "onProviderEnabled");
        }

        @Override
        public void onStatusChanged(String provider, int status,
                Bundle extras) {
            Log.d("myLogs", "onStatusChanged");

        }

    }

}
4

1 回答 1

2

不幸的是,默认情况下 GPS 不是很可靠,但在室外环境中应该精确到 5-10 米;正如您可能想象的那样,室内情况甚至更糟。很多人报告说,他们甚至无法在室内环境中接收坐标。

不幸的是,GPS 精度还取决于手头的智能手机和天气条件,因此实际上没有确定确切精度的具体方法。

所以我最好的猜测是,根本不可能获得比您目前收到的更好的结果。

对不起(我猜)

于 2013-09-23T19:28:43.847 回答