tags:

views:

110

answers:

2

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
    }
}    

}

+1  A: 

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

Karol Wilk
HI kwa...I want to do this on real device not on emulator
Does AnyOne Help me..?
A: 

Can't post comments yet, so sorry for extra anwser ^^

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

Tseng
Yeah I enabled it..But its not working..