title: Fake location using GPS in android
body: <p>Hi am developing an app that will set the coordinates(latitude and longitude). And it has to show my location as i am at that coordinates..It is similar to location spoofer.. <a href="http://www.androidzoom.com/android_applications/tools/location-spoofer_gkmc.html" rel="nofollow">http://www.androidzoom.com/android_applications/tools/location-spoofer_gkmc.html</a>
  But I am failing to do that.. here is my code..Please any one help me.</p>
  
  <pre><code>public class Mock extends MapActivity 
  {    
    private LocationManager lm;
    private LocationListener locationListener;
  
    private MapView mapView;
    String mocLocationProvider;
    private MapController mc;
  
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main); 
  
      //---use the LocationManager class to obtain GPS locations---
      lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);    
  
     locationListener = new MyLocationListener();
  
      mocLocationProvider=LocationManager.GPS_PROVIDER;
  
      lm.addTestProvider(mocLocationProvider, false, false,false, false, true, true, true, 0, 5);
      lm.setTestProviderEnabled(mocLocationProvider,true);
      lm.requestLocationUpdates(mocLocationProvider,0,0,locationListener);
  
  
      mapView = (MapView) findViewById(R.id.mapview1);
      mc = mapView.getController();
  
    }
  
    @Override
    protected boolean isRouteDisplayed() {
      // TODO Auto-generated method stub
      return false;
    }        
  
    private class MyLocationListener implements LocationListener 
    {
      @Override
      public void onLocationChanged(Location loc) {
  
          loc = new Location(mocLocationProvider);
  
           Double latitude = 1.352566007;
           Double longitude = 103.78921587;
  
           //Double altitude = Double.valueOf(parts[2]);
  
           loc.setLatitude(latitude);
           loc.setLongitude(longitude);
           loc.setTime(System.currentTimeMillis());
           lm.setTestProviderLocation(mocLocationProvider, loc);
  
  
              mc.setZoom(16);                
              mapView.invalidate();
  
      }
  
      @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
      }
  }    
  }
  </code></pre>