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
The already mentioned multiple times answer to use the shell command "geo fix..." is the correct answer. But in case you use LocationClient.getLastLocation() to retrieve your data it is worth to mention that it will not work at first. The LocationClient class uses the Google Play Service to retrieve the coordinates. For me this started working after running the emulators maps app once. During the first start you are asked to allow google apps access to your location, which I guess does the trick.
In Mac, Linux or Cygwin:
echo 'geo fix -99.133333 19.43333 2202' | nc localhost 5554
That will put you in Mexico City. Change your longitude/latitude/altitude accordingly. That should be enough if you are not interested in nmea.
See Obtaining User Location
Look under Providing Mock Location Data. You will find the solution for it.
You can use an emulator like genymotion which gives you the flexibility to emulate your present GPS location, etc.
Dalvik Debug Monitor > Select Emulator > Emulator Control Tab > Location Controls.
DDMS -- android_sdk/tools/ddms OR android_sdk/tools/monitor
No one here mentioned the built in solution of the emulator itself, so for future visitors, I'd like to share it with visuals.
First, run your Android Emulator and click on the menu button (3 dots) shown below:
Then from the left pane, select Location and change the coordinates according to your needs. After pressing Send button, changes will immediately take effect (I recommend you to open up Google Maps for better understanding).
Android Studio Version: 2.3.3
In addition, to make your different locations coming to your application in real time, you can use GPX file. It's very easy to create this file from Google Map direction link:
Use "Load GPS/KML" button to load the created file to your emulator, choose speed, and press green play button on the bottom. Locations will be sent in real time as shown on the picture below.