I have been trying to use this feature available under the developer options on a android device. i am a tester so trying to fake a location on android device. I have already given permission ACCESS_MOCK_LOCATION under android manifest permissions. Not sure what and where should i put my fake longitude and latitude in my code. does anyone have tried it before? I am new to code and a tester so don't have idea what code should i write for fake long and lat and where should i put it. I have the source code for my test app and its a health app with maps on the home screen.
Asked
Active
Viewed 727 times
1 Answers
1
After instantiating your LocationClient
you can call locationclient.setMockMode(true);
After that you can have your code generate Location
objects like so
public Location createLocation(double lat, double lng, float accuracy) {
// Create a new Location
Location newLocation = new Location(PROVIDER);
newLocation.setLatitude(lat);
newLocation.setLongitude(lng);
newLocation.setAccuracy(accuracy);
return newLocation;
}
After that you could do something like
Location testLocation = createLocation(12.34, 45.679, 9.0f);
and
locationClient.setMockLocation(testLocation);
(This is taken from here)
This blog describes how to use mock locations when debugging and turning them off when not debugging.

Dave
- 1,784
- 2
- 23
- 35
-
Do you know where to put this code in the source code? – LearningCode Jun 02 '14 at 21:07
-
This code will go where your application has its location logic. Apart from using mock locations you can run your code in an android emulator from the android sdk and use telnet to send location data to the emulator (see http://stackoverflow.com/a/2279827/2822762) – Dave Jun 02 '14 at 21:44