I want to get longitude and latitude in Android emulator for testing.
Can any one guide me how to achieve this?
How do I set the location of the emulator to
1. Android Studio users.
After running the emulator goto Tools->Android->Android device monitor
Click the Emulator Control Tab change from the location controls group.
2. Eclipse users.
First In Eclipse In Menu Select "Window" then Select "Open Perspective" then Select "DDMS". i.e Window->Open Prespective->DDMS.
You will see on Left Side Devices Panel and on Right Side you will see different tabs. Select "Emulator Control" Tab.
At bottom you will see Location Controls Panel. Select "Manual" Tab.
Enter Longitude and Latitude in Textboxs then Click Send Button. It will send the position to you emulator and the application.
3. Using telnet.
In the run command type this.
telnet localhost 5554
If you are not using windows you can use any telnet client.
After connecting with telnet use the following command to send your position to emulator.
geo fix long lat
geo fix -121.45356 46.51119 4392
4. Use the browser based Google maps tool
There is a program that uses GWT and the Google Maps API to launch a browser-based map tool to set the GPS location in the emulator:
android-gps-emulator
Using the "geo" command in the emulator console
To send mock location data from the command line:
Launch your application in the Android emulator and open a terminal/console in your SDK's /tools directory.
Connect to the emulator console:
telnet localhost 5555
(Replace 5555 with whatever port your emulator is running on)
Send the location data: * geo fix to send a fixed geo-location.
This command accepts a longitude and latitude in decimal degrees, and an optional altitude in meters. For example:
geo fix -121.45356 46.51119 4392
There is a plugin for Android Studio called “Mock Location Plugin”. You can emulate multiple points with this plugin. You can find a detailed manual of use in this link: Android Studio. Simulate multiple GPS points with Mock Location Plugin
I wrote a python script to push gps locations to the emulator via telnet. It defines a source and a destination location. There is also a time offset which lets you control how long coordinates will be pushed to the device. One location is beeing pushed once a second.
In the example below the script moves from Berlin to Hamburg in 120 seconds. One step/gps location per second with random distances.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import telnetlib
from time import sleep
import random
HOST = "127.0.0.1"
PORT = 5554
TIMEOUT = 10
LAT_SRC = 52.5243700
LNG_SRC = 13.4105300
LAT_DST = 53.5753200
LNG_DST = 10.0153400
SECONDS = 120
LAT_MAX_STEP = ((max(LAT_DST, LAT_SRC) - min(LAT_DST, LAT_SRC)) / SECONDS) * 2
LNG_MAX_STEP = ((max(LNG_DST, LNG_SRC) - min(LNG_DST, LNG_SRC)) / SECONDS) * 2
DIRECTION_LAT = 1 if LAT_DST - LAT_SRC > 0 else -1
DIRECTION_LNG = 1 if LNG_DST - LNG_SRC > 0 else -1
lat = LAT_SRC
lng = LNG_SRC
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
tn.set_debuglevel(9)
tn.read_until("OK", 5)
tn.write("geo fix {0} {1}\n".format(LNG_SRC, LAT_SRC))
#tn.write("exit\n")
for i in range(SECONDS):
lat += round(random.uniform(0, LAT_MAX_STEP), 7) * DIRECTION_LAT
lng += round(random.uniform(0, LNG_MAX_STEP), 7) * DIRECTION_LNG
#tn.read_until("OK", 5)
tn.write("geo fix {0} {1}\n".format(lng, lat))
#tn.write("exit\n")
sleep(1)
tn.write("geo fix {0} {1}\n".format(LNG_DST, LAT_DST))
tn.write("exit\n")
print tn.read_all()
For Android Studio users:
run the emulator,
Then, go to Tools -> Android ->Android device monitor
open the Emulator Control
Tab, and use the location controls group.
If you're using Eclipse
, go to Window->Open Perspective->DDMS
, then type one in Location Controls
and hit Send
.