Fake GPS Location on Android

Hi, I am creating an application that will set the coordinates (latitude and longitude). And he must show my location, as I am in these coordinates. It looks like the location of the trigger. http://www.androidzoom.com/android_applications/tools/location-spoofer_gkmc.html But I canโ€™t do this .. here is my code ... Please 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 } } } 
+4
source share
2 answers

Basically, you set the coordinates on a real device in the same way as in an emulator, using DDMS in Eclipse.

Just make sure you activate โ€œfake locationsโ€ on your device. You can find the setting in Settings> Applications> Development> Allow Location Layout .

0
source

All Articles