1

Now I am working with location based app and my problem is that the location is not updated on the real device. That is the onLocationChanged not working on real device. But fine on emulator.

    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

        }
    }

Please help me.

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56

1 Answers1

1

I just used NETWORK_PROVIDER instead of GPS_PROVIDER. Because GPS is not available in all locations. In my case it solved my problem perfectly. We just need an active internet connection in our mobile.

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
  • GPS is available everywhere as long as you are in open. Where the signal cannot be interfere from something from your sides or above you, like underground, tall buildings, indoors. – Nikola Despotoski Aug 03 '13 at 14:57