【问题标题】:onLocationChanged is not working on real deviceonLocationChanged 在真实设备上不起作用
【发布时间】:2013-03-31 15:04:35
【问题描述】:

现在我正在使用基于位置的应用程序,我的问题是位置没有在真实设备上更新。那就是onLocationChanged 不在真实设备上工作。但在模拟器上很好。

    locmngr=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
            loclis =new MyLocationListner();
            our_location=locmngr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locmngr.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0,loclis);
public class MyLocationListner implements LocationListener{

        @Override
        public void onLocationChanged(Location location)
        {
            // TODO Auto-generated method stub
            L1=location.getLatitude();
            L2=location.getLongitude();
            String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
            //          Toast.makeText(getApplicationContext(), currentDateTimeString, Toast.LENGTH_SHORT).show();
            DatabaseHandlerActivity db = new DatabaseHandlerActivity(getApplicationContext());
            db.addLocation(new Locations_viewer(L1.toString(), L2.toString(), currentDateTimeString));

                        Toast.makeText(getApplicationContext(), "New Location   "+"Latitude ="+L1+
                                "   Longitude ="+L2, Toast.LENGTH_LONG).show();


            Calendar c = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String formattedDate = df.format(c.getTime());


            ParseUser.getCurrentUser().put("Latitude", L1.toString());
            ParseUser.getCurrentUser().put("Longitude", L2.toString());

            ParseUser.getCurrentUser().put("Time", formattedDate);


            ParseUser.getCurrentUser().saveInBackground();

            //          Toast.makeText(getApplicationContext(), "Latitude ="+L1, Toast.LENGTH_LONG).show();
            //          Toast.makeText(getApplicationContext(), "Longitude ="+L2, Toast.LENGTH_LONG).show();



        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }
    }

请帮帮我。

【问题讨论】:

  • GPS 可用吗?有什么例外吗?
  • GPS 已开启,也不例外
  • 我在城里转了一圈,没工作
  • 到底是什么问题? onLocationChanged() 没有被调用?
  • 是的..它没有触发! :( 它在模拟器中运行良好'

标签: android location locationmanager


【解决方案1】:

我只是使用NETWORK_PROVIDER 而不是GPS_PROVIDER。因为 GPS 并非在所有位置都可用。就我而言,它完美地解决了我的问题。我们只需要在我们的手机中建立有效的互联网连接即可。

【讨论】:

  • GPS 在任何地方都可以使用,只要您处于开放状态。信号不会受到来自您侧面或上方的物体的干扰,例如地下、高层建筑、室内。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 2020-07-03
  • 2012-07-06
  • 1970-01-01
  • 2011-05-23
相关资源
最近更新 更多