Fake GPS location (on real device)

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Fake GPS location (on real device)

Postby MrAdam » Mon Mar 01, 2010 1:29 am

Hi everyone. For the last 2 days i've been trying to find a way to create an app that can fake the GPS location on my android phone. I have been trying to use LocationManager. But can't seem to get it to work... and haven't found any examples on the internet, only for the emulator.
So i was just wondering if it is even possible? and if you have any examples that i could have a look at.

Regards, Adam.

P.S. Im developing for 1.5
MrAdam
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 01, 2010 1:24 am

Top

Postby MrAdam » Wed Mar 03, 2010 4:22 pm

so... got it to work, but only on 1.5..

Code: Select all
public void clearLocation() {
     LocationManager locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
     locMan.clearTestProviderLocation("gps");


The following code only works on 1.5
1.6 and 2.1 just FC when running it...
MrAdam
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 01, 2010 1:24 am

Postby nicholas.hauschild » Thu Mar 04, 2010 2:22 pm

Hello MrAdam,

Could you provide some more information (like a stacktrace from logcat, or perhaps a larger chunk of the source) to help us identify the problem?

Good Luck :)
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby MrAdam » Thu Mar 04, 2010 3:42 pm

[s]Well... I noticed that the LOCATION_SERVICE provider returns null, and not "gps" in systems newer than 1.5[/s]

Never mind.. it does return "gps" in both 1.6 and 2.1

---------------------------------
Code: Select all
String mocLocationProvider = locationManager.GPS_PROVIDER;
locationManager.setTestProviderEnabled(mocLocationProvider, true);

The following crashes in 2.1, but works without error in 1.5.
Still can't seem to find out whats wrong...

My first guess would be that i need to do something more than setting <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> in my manifest... but i don't know what.
MrAdam
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 01, 2010 1:24 am

Postby MrAdam » Thu Mar 04, 2010 5:12 pm

okay... strange..

the following code crashes in 1.5, but works without errors in 2.1..

Code: Select all
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String mocLocationProvider = locationManager.GPS_PROVIDER;
locationManager.addTestProvider(mocLocationProvider, false, false, false, false, false, false, false, 0, 5);


After adding this code, all the other commands my application runs works perfectly on 2.1.
but still... in 1.5 it crashes if i run this first..
MrAdam
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 01, 2010 1:24 am

Postby MrAdam » Thu Mar 04, 2010 6:25 pm

[s]Got it to work :D
don't ask me how... have no idea myself... but code works now xD[/s]

The problem was that i was using the "gps" provider.
And it seems that since android 1.5 you can't set it's latitude and longitude anymore.

So i created a new provider. But google maps still uses the old "gps" provider.
So i tried removing the "gps" provider, only to find out that now gps wasn't functioning in google maps.
And i has to reboot my phone to get it to work again.

Is there any way to set which provider the system should use by default?

here is some code from my app:
Code: Select all
public void setLocation(double latitude, double longitude) {
   if (locationManager.getProvider("spoof") == null) {
           locationManager.addTestProvider("spoof", false, true, false, false, false, false, false, 0, 5);
           locationManager.setTestProviderEnabled("spoof", true);
       }
        Location loc = new Location("spoof");
        loc.setTime(System.currentTimeMillis());
        loc.setLatitude(latitude);
        loc.setLongitude(longitude);
        locationManager.setTestProviderLocation("spoof", loc);   
    }

The above code is used to create my own TestProvider.
What i want is for the phone to use that instead of the default "gps" provider, as i can't acces "gps" in systems newer than 1.5
MrAdam
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 01, 2010 1:24 am

Top

Re: Fake GPS location (on real device)

Postby m0thman » Wed Jul 28, 2010 10:05 pm

Hi there,

Did you get any joy with this. Trying to do a similar thing myself. Google Maps seems to ignore all my attempts to spoof the location with a mock provider.
m0thman
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jul 28, 2010 10:04 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: Google [Bot] and 2 guests