4

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.. http://www.androidzoom.com/android_applications/tools/location-spoofer_gkmc.html But I am failing to do that.. here is my code..Please any one help me.

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
    }
}    
}
Legend
  • 113,822
  • 119
  • 272
  • 400
user458295
  • 1,239
  • 4
  • 12
  • 11

2 Answers2

2

I would use this method http://developer.android.com/guide/developing/tools/ddms.html#emulator-control. Haven't tried this one: http://code.google.com/p/android/issues/detail?id=915

bgs
  • 1,210
  • 10
  • 19
  • 1
    HI kwa...I want to do this on real device not on emulator – user458295 Sep 26 '10 at 03:21
  • 5
    Downvote to BGS - no offense. Should have followed up on the user's question here. Yes, you can do this on the real device. Just enable "mock locations" in settings, and follow the guide at the first URL in this answer under how to run DDMS. You'll have to enable USB debugging as well for the computer to recognize the device. Make sure to have installed the OEM USB drivers for your phone (which I'm sure you've already done). – Qix - MONICA WAS MISTREATED Aug 24 '11 at 10:29
  • 2
    And yes I know I'm about a year late, but I thought someone might find this helpful. – Qix - MONICA WAS MISTREATED Aug 24 '11 at 10:29
  • It is Qix... It is... It's 2013 and I do find it useful – Michael 'Maik' Ardan May 22 '13 at 08:48
0

You basically set the coordinates on real device in the same way you do in the emulator by using DDMS in Eclipse.

Just make sure you enable "fake locations" in your device. You can find the setting at Settings > Applications > Development > Allow mock locations.

Chris Frederick
  • 5,482
  • 3
  • 36
  • 44
Tseng
  • 61,549
  • 15
  • 193
  • 205