Пример #1
0
 @Override
 public void onProviderDisabled(String provider) {
   if ((LocationManager.GPS_PROVIDER.equals(provider)
           && !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
       || (LocationManager.NETWORK_PROVIDER.equals(provider)
           && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))) {
     latitudeE6 = Integer.MAX_VALUE;
     longitudeE6 = Integer.MAX_VALUE;
     if (iMain != null) {
       try {
         iMain.setCoordinates(latitudeE6, longitudeE6);
       } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     } else {
       // TODO notify about no GPS
     }
   }
 }
  @Override
  public void onLocationChanged(Location location) {
    if (DEBUG) Log.d(TAG, location.toString());
    String provider = location.getProvider();
    if (LocationManager.GPS_PROVIDER.equals(provider)) {
      mLocation = new Location(location);
      if (mStartTime == 0) {
        mStartTime = System.currentTimeMillis();
        Message msg = Message.obtain(mHandler, MSG_REPORT_LOCATION);
        // Improve the precision, collect location after 3 second.
        mHandler.sendMessageDelayed(msg, 3100);

        // When get first position, set self stop timer
        mHandler.sendEmptyMessageDelayed(MSG_STOP_SELF, mTrack * mPrecise * 1000 + 5000);
      } else {
        long current = System.currentTimeMillis();
        long elapse = current - mStartTime;
        if (elapse > (mPrecise * 1000)) {
          mStartTime = current;
          Message msg = Message.obtain(mHandler, MSG_REPORT_LOCATION);
          mHandler.removeMessages(MSG_REPORT_LOCATION);
          mHandler.sendMessage(msg);
        } else {
          Message msg = Message.obtain(mHandler, MSG_REPORT_LOCATION);
          mHandler.removeMessages(MSG_REPORT_LOCATION);
          mHandler.sendMessageDelayed(msg, mPrecise * 1000 - elapse);
        }
      }
    } else if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
      // only update network once
      // if (mNetworkLocation == null) {
      mNetworkLocation = new Location(location);
      Message msg = Message.obtain(mHandler, MSG_REPORT_COARSE_LOCATION);
      mHandler.sendMessage(msg);
      // }
    }
  }
Пример #3
0
 @Override
 public void onProviderEnabled(String provider) {
   if (LocationManager.GPS_PROVIDER.equals(provider)
       || LocationManager.NETWORK_PROVIDER.equals(provider)) initLocationUpdates(provider);
 }