title: mock location for testing geofence apps
body: <p>I am developing  a very basic app where I am creating a geofence of 5000m radius keeping my location as the center.</p>
  
  <pre><code>    public class MainActivity extends ActionBarActivity implements
      GooglePlayServicesClient.ConnectionCallbacks,
      GooglePlayServicesClient.OnConnectionFailedListener, LocationListener,
      com.google.android.gms.location.LocationListener,
      LocationClient.OnAddGeofencesResultListener {
  
  private LocationClient mLocationClient;
  private LocationRequest mLocationRequest;
  // Milliseconds per second
  private static final int MILLISECONDS_PER_SECOND = 1000;
  // Update frequency in seconds
  public static final int UPDATE_INTERVAL_IN_SECONDS = 5;
  // Update frequency in milliseconds
  private static final long UPDATE_INTERVAL = MILLISECONDS_PER_SECOND
          * UPDATE_INTERVAL_IN_SECONDS;
  // The fastest update frequency, in seconds
  private static final int FASTEST_INTERVAL_IN_SECONDS = 1;
  // A fast frequency ceiling in milliseconds
  private static final long FASTEST_INTERVAL = MILLISECONDS_PER_SECOND
          * FASTEST_INTERVAL_IN_SECONDS;
  
  boolean mUpdatesRequested;
  private Editor mEditor;
  private SharedPreferences mPrefs;
  private List&lt;Geofence&gt; mGeofenceLists = new ArrayList&lt;Geofence&gt;();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_list_item);
  
      mUpdatesRequested = false;
      mPrefs = getPreferences(MODE_PRIVATE);
      mEditor = mPrefs.edit();
  
      // Create the LocationRequest object
      mLocationRequest = LocationRequest.create();
      // Use high accuracy
      mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
      // Set the update interval to 5 seconds
      mLocationRequest.setInterval(UPDATE_INTERVAL);
      // Set the fastest update interval to 1 second
      mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
  
      // Location Client Object
      mLocationClient = new LocationClient(this, this, this);
  
  }
  
  @Override
  protected void onStart() {
      super.onStart();
      // Connect the client.
      mLocationClient.connect();
  }
  
  @Override
  protected void onStop() {
      // Disconnecting the client invalidates it.
      mLocationClient.disconnect();
      super.onStop();
  }
  
  @Override
  protected void onPause() {
      // TODO Auto-generated method stub
      super.onPause();
      // Save the current setting for updates
      mEditor.putBoolean("KEY_UPDATES_ON", mUpdatesRequested);
      mEditor.commit();
      super.onPause();
  }
  
  @Override
  protected void onResume() {
      // TODO Auto-generated method stub
      super.onResume();
  
      /*
       * Get any previous setting for location updates Gets "false" if an
       * error occurs
       */
      if (mPrefs.contains("KEY_UPDATES_ON")) {
          mUpdatesRequested = mPrefs.getBoolean("KEY_UPDATES_ON", false);
  
          // Otherwise, turn off location updates
      } else {
          mEditor.putBoolean("KEY_UPDATES_ON", false);
          mEditor.commit();
      }
  }
  
  @Override
  public void onConnectionFailed(ConnectionResult result) {
      // TODO Auto-generated method stub
      System.out.println("DISCONNECTED!!!!!!!!!!!!!!!!!!");
  }
  
  @Override
  public void onConnected(Bundle connectionHint) {
      // TODO Auto-generated method stub
  
      // Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
  
      // Toast.makeText(this,"lat:  "+location.getLatitude()+"       long: "+location.getLongitude(),
      // Toast.LENGTH_LONG).show();
      /*
       * try { getAddress(); } catch (IOException e) { // TODO Auto-generated
       * catch block e.printStackTrace(); }
       */
      // If already requested, start periodic updates
  
      // Location location = mLocationClient.getLastLocation();
  
      Geofence geofence = new Geofence.Builder().setRequestId("geo1")
              .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
              .setCircularRegion(89.535354, -88.575510, 5000)
              .setExpirationDuration(Geofence.NEVER_EXPIRE).build();
  
      mGeofenceLists.add(geofence);
      mLocationClient.addGeofences(mGeofenceLists,
              getTransitionPendingIntent(), this);
  
      if (true) { // Need to update when user is asking for updates with
                  // mUpdatesRequested
          mLocationClient.requestLocationUpdates(mLocationRequest, this);
  
      }
  
  }
  
  private PendingIntent getTransitionPendingIntent() {
      // Create an explicit Intent
      PendingIntent geoFencePendingIntent = PendingIntent.getService(this, 0,
              new Intent(this, TransitionsIntentService.class),
              PendingIntent.FLAG_UPDATE_CURRENT);
      return geoFencePendingIntent;
  
  }
  
  /*
   * private void getAddress() throws IOException { // TODO Auto-generated
   * method stub
   * 
   * double latitude = mLocationClient.getLastLocation().getLatitude(); double
   * longitude = mLocationClient.getLastLocation().getLongitude(); Geocoder
   * geocoder; List&lt;Address&gt; addresses; geocoder = new Geocoder(this,
   * Locale.getDefault()); addresses = geocoder.getFromLocation(latitude,
   * longitude, 1);
   * 
   * String address = addresses.get(0).getAddressLine(0); String city =
   * addresses.get(0).getAddressLine(1); String country =
   * addresses.get(0).getAddressLine(2);
   * 
   * 
   * Toast.makeText(this,"You are at :  "+address+"\n"+city+" ,"+country,
   * Toast.LENGTH_SHORT).show();
   * 
   * 
   * }
   */
  
  @Override
  public void onDisconnected() {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onLocationChanged(Location location) {
      // TODO Auto-generated method stub
  
      // System.out.println("LOCATION CHANGE TRIGGERED!!!!!!!!!!!!!!!");
      /*
       * String msg = "Updated Location: " +
       * Double.toString(location.getLatitude()) + "," +
       * Double.toString(location.getLongitude()); Toast.makeText(this, msg,
       * Toast.LENGTH_SHORT).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
  
  }
  
  public class GeofenceSampleReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
  
          String action = intent.getAction();
  
          if (TextUtils.equals(action,
                  "com.example.android.geofence.ACTION_GEOFENCE_TRANSITION")) {
  
              /* handleGeofenceTransition(context, intent); */
  
              System.out
                      .println("!!!!!!!!!!!!!!!!!!GEOFENCE in sample receiverTRIGGERED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  
          }
      }
  
  }
  
  public class TransitionsIntentService extends IntentService {
      public static final String TRANSITION_INTENT_SERVICE = "ReceiveTransitionsIntentService";
  
      public TransitionsIntentService() {
          super(TRANSITION_INTENT_SERVICE);
      }
  
      @Override
      protected void onHandleIntent(Intent arg0) {
          // TODO Auto-generated method stub
  
  
  
          System.out
          .println("!!!!!!!!!!!!!!!!!!GEOFENCE in handle intent TRIGGERED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  
  
      }
  }
  
  @Override
  public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am not getting any triggering in the code.Is it because I am already inside the geofence???
  How can I test the entry and exit point with the geofence I have created.</p>