This post will guide you through the steps of setting up fake GPS on the Google Android emulator
.
Set permissions in AndroidManifest.xml:
Find the correct local port for your Android emulator:
$ adb devices
List of devices attached
emulator-5554 device
The port we are looking for is in this case 5554. Now connect via telnet:
$ telnet localhost 5554
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
Set your preferred location manually: You set the location with the geo fix command:
geo fix $longitude $latitude
For example the city center of Barcelona:
geo fix 2.169919 41.387917
OK
To get the latitude and longitude you want simply go to http://maps.google.com on your computer's web browser, move the desired location to the center of your screen and simply enter this little JavaScript command into the address bar:
CAUTION: the format of the coordinates you get from Google Maps is ($latitude, $longitude) - but the way you enter the geo fix for Android has longitude and latitude switched around.
Make sure everything works properly:
Just launch the Google Maps application in your emulator. It should take you directly to the location you entered and display a blue blinking light.
Access Android's Location Service in your application:
Notes:
- I noticed that sometimes the manully entered location dissolves. I haven't looked into that yet, but a workaround for now is to simply re-enter the location via the geo fix command again.
- You always mix up latitude and longitude?
- Latitude: goes from East<>West, like the rungs of a ladder (→ sounds similar to latitude)
- Longitude: runs from North<>South. Think of the globe as a big, fat guy with a long (→ longitude) tie hanging down from the North Pole.
I've just launched a new side project of mine:
Bugfender - A modern remote logger tailor-made for mobile development
It's currently free and you can sign up here: https://app.bugfender.com/signup
Any kind of feedback is more than appreciated :-)
Your tip for not mixing up latitude and longitude is mixed up...
ReplyDeletehttp://en.wikipedia.org/wiki/File:Latitude_and_Longitude_of_the_Earth.svg
Nope. Both my explanation and the Wikipedia image are correct. However, the Wikipedia image is a bit confusing, because it doesn't mean the direction of latitude or longitude, but in which way they increase.
ReplyDelete