title: Insert location coordinates into database after every 1 minute for that device
body: <p>I am working on the application in which I need to store the <code>location</code> in the database after every <code>1 minute</code> for that particular <code>device/user</code>. </p>
  
  <p>Suppose if user is moving while the application is open then his coordinates should keep on getting inserted into database after every <code>1 minute</code>. So for that I have my Web Services setup which can insert the data into the MySql Database. I have tested my WebService in the insertion part, it works fine.</p>
  
  <p>But the problem that I am having is- I don't think so it is inserting into MySql database for that particular device/user after every <code>1 minute</code>. Can anyone tell me why it is not happening after every <code>1 minute</code>? And if there is any problem in the below code, can anyone help me out here by providing some example which will work as per my scenario above?</p>
  
  <p>Any thoughts will be of great help.</p>
  
  <pre><code>private final String id = UUID.randomUUID().toString();
  private final String sampleURL = ServerInfo.getServiceURL() + "/insert";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);    
  
      locationListener = new GPSLocationListener();
  
      locationManager.requestLocationUpdates(
              LocationManager.GPS_PROVIDER, 
              60000, 
               0, 
              this.locationListener);
  
  }
  </code></pre>
  
  <p>Below is the class that implements <code>LocationListener</code>.</p>
  
  <pre><code>private class GPSLocationListener implements LocationListener {
      @Override
      public void onLocationChanged(Location location) {
          if (location != null) {
              GeoPoint point = new GeoPoint(
                      (int) (location.getLatitude() * 1E6), 
                      (int) (location.getLongitude() * 1E6));
                  }
       // Below code is used to insert into database
              String userId = id;
              String mLatitude = Double.toString(location.getLatitude());
              String mLongitude = Double.toString(location.getLongitude());
              String mProvider = location.getProvider();
              String mHasAltitude = Boolean.toString(location.hasAltitude());
              String mAltitude = Double.toString(location.getAltitude());
              String mHasSpeed = Boolean.toString(location.hasSpeed());
              String mSpeed = Float.toString(location.getSpeed());
              String mHasBearing = Boolean.toString(location.hasBearing());
              String mBearing = Float.toString(location.getBearing());
              String mHasAccuracy = Boolean.toString(location.hasAccuracy());
              String mAccuracy = Float.toString(location.getAccuracy());
  
              WebServiceTask wst = new WebServiceTask(WebServiceTask.POST_TASK,
                      getApplicationContext(), "Posting data...");
  
              wst.addNameValuePair("user_id", userId);
              wst.addNameValuePair("mlatitude", mLatitude);
              wst.addNameValuePair("mlogitude", mLongitude);
              wst.addNameValuePair("mprovider", mProvider);
              wst.addNameValuePair("mhasAltitude", mHasAltitude);
              wst.addNameValuePair("mAltitude", mAltitude);
              wst.addNameValuePair("mhasspeed", mHasSpeed);
              wst.addNameValuePair("mspeed", mSpeed);
              wst.addNameValuePair("mhasbearing", mHasBearing);
              wst.addNameValuePair("mbearing", mBearing);
              wst.addNameValuePair("mhasaccuracy", mHasAccuracy);
              wst.addNameValuePair("maccuracy", mAccuracy);
  
              // This will insert into database
              wst.execute(new String[] { sampleURL });
  
  
      }
  
      @Override
      public void onProviderDisabled(String provider) {
      }
  
      @Override
      public void onProviderEnabled(String provider) {
      }
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras) {
      }
  }
  </code></pre>
  
  <p><strong>NOTE:-</strong>  It is inserting into Database but it's not inserting at exactly or approximately in the time interval I need which is of <code>1 minute</code></p>