How to set the location manually in Android Studio emulator
Asked Answered
O

9

19

I have a project in which I need to get the location as India. But in my emulator I am not getting the location.

  • I need to get the location as India
  • when I take the google maps from my emulator, it is showing the current location in middle of the sea.

    API level I am using is 27.
    Emulator I use is Nexus 5x.
    

how to get the current position in this Emulator and also manually.

I tried to edit the location in Emulator and tried to give the latitude and longitude but it is not working.

Orobanchaceous answered 28/11, 2017 at 9:26 Comment(2)
You can find the answer hereTestes
Check these Links #38247850 #39205453 #18972614Apocryphal
R
27

In 2020 with Android Studio 3.6, the way I had to change the emulator location is slightly different than accepted answer. Here how it is:

First,

click more on emulator

Second, Location is first menu item and it is selected by default. You have to select your location in the map and save that point.

tap on map and set your location point

Third, select the saved point and press on select location button in bottom right corner.

change emulator location

That's it, close that window. You are all done.

Sometimes you may have to close the emulator and open (Not restart).

Roeder answered 3/5, 2020 at 10:42 Comment(11)
You can set it visually but the longitude and latitude will still be somewhere in America if i log it inside my applicationMoises
Yes, that is the Mountain View location after these changes yetGains
It is not working. It still gives Mountain View location.Pogge
I have only one location added, saved it and set it as SET Location.Pogge
Still not working after set a new location, I tried also with reset.Semblance
@A.Amini you must restart emulator to take effectRoeder
@SriramNadiminti, I also have this bug: #64354681. Have you fixed this behaviour?Livre
@Livre - No. I couldn't.Pogge
@SriramNadiminti Did you tried closing and opening emulator after suggested steps?Roeder
@Blasanka. Yes I have. Even restarted the Android StudioPogge
For me, closing the Extended controls window made it workVanhook
I
26

First of all,

  • Restart your emulator.
  • Go to More > Location. Enter your lat-long > Press SEND

enter image description here

Illdisposed answered 28/11, 2017 at 11:33 Comment(2)
tried that many times.. doesn't works, after setting it when i look at google map its still says the current location is in americaOrobanchaceous
As of this writing, those location controls no longer exist in Android Studio Dolphin | 2021.3.1 Patch 1.Civilization
E
5

In my case; until i login my Google account on emulator, location not changed. After login, it's changed. I think it's about Google Services.

Elohist answered 18/10, 2020 at 10:35 Comment(1)
This worked for me, i just logged in with my google account on the emulatorDarcee
A
4

You can set Location using Command prompt or ADB

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

geo fix 2.169919 41.387917
OK

ANOTHER EASY WAY

Open Android Device Monitor From Android Studio.

Select the Emulator.

Select Emulator Control

In Emulator Control Select Location Control

Select Manual

In that Give your Longitude and Latitude

Apocryphal answered 28/11, 2017 at 9:41 Comment(5)
when i tried to give the command - geo fix 2.169919 41.387917 , iam getting error:- Android Console: Authentication required Android Console: type 'auth <auth_token>' to authenticate Android Console: you can find your <auth_token> in 'C:\Users\martin\.emulator_console_auth_token' OK - what to do with this error @Tomin BOrobanchaceous
@Martinj Try the next method. Using Android Device Monitor. Second Method will Work for SureApocryphal
when i clicked the android device monitor nothing comesOrobanchaceous
the ADM has everything grayed out for emulator control. the emulator lets you type and press buttons with gps coords, but it has no affectChime
@Martinj Ops forgot to say that you also need to restart emulator. Did you?Roeder
C
0

In my case, setting the point and restarting the emulator, then signin in to Google account and checking my location in Chrome directly was the solution.

Catwalk answered 28/5, 2021 at 11:18 Comment(0)
A
0

I solved this by wiping the emulator's data and restarting it.

Alate answered 14/9, 2022 at 14:36 Comment(0)
H
0

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

geo fix 2.169919 41.387917
OK

If you are having authentication required issue, then:

Android Console: Authentication required
Android Console: type 'auth <auth_token>' to authenticate
Android Console: you can find your <auth_token> in
'C:\Users\Administrator\.emulator_console_auth_token' <--you will find your auth code here
OK
auth PsL*******QML <---pass auth with your authentication code then enter 
Android Console: type 'help' for a list of commands
OK
geo fix your_desired_long your_desired_lat <--then this
OK

Or you can also do like this:

adb -s emulator-5554 emu geo fix <longitude> <latitude>
your emulator name-> like emulator-5554
adb -s emulator-5554 emu geo fix -122.0838 37.4220
Humane answered 17/11, 2023 at 6:59 Comment(0)
M
0

I gave all permissions and set manually location as what Blasanka said. Then signed in my google account(Not solved my problem) then I just tried to find my own location on GoogleMaps on emulator was solved rest of the problems.

Melanism answered 6/4 at 11:49 Comment(0)
V
-1

set force Android Location Manager to true. Like this "position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.low, forceAndroidLocationManager: true);" then you will get the location on emulator.

Velocity answered 8/5, 2021 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.