How to emulate GPS location in the Android Emulator?

前端 未结 30 2392
天命终不由人
天命终不由人 2020-11-21 22:15

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

相关标签:
30条回答
  • 2020-11-21 22:42

    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.

    0 讨论(0)
  • 2020-11-21 22:43

    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.

    0 讨论(0)
  • 2020-11-21 22:43

    See Obtaining User Location

    Look under Providing Mock Location Data. You will find the solution for it.

    0 讨论(0)
  • 2020-11-21 22:43

    You can use an emulator like genymotion which gives you the flexibility to emulate your present GPS location, etc.

    0 讨论(0)
  • 2020-11-21 22:47

    Dalvik Debug Monitor > Select Emulator > Emulator Control Tab > Location Controls.

    DDMS -- android_sdk/tools/ddms OR android_sdk/tools/monitor

    0 讨论(0)
  • 2020-11-21 22:48

    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:

    1. Go to google map, choose a location, then press "Directions" and enter the second location.
    2. After route is created, copy a link from the browser
    3. Go to this website: https://mapstogpx.com and paste the link to "Let's Go" box
    4. Press the "Let's Go" button and GPX file will be downloaded

    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.

    0 讨论(0)
提交回复
热议问题