Emulator's Location simulation not working
Asked Answered
B

14

80

I would like to lower the minimum API level of my application to 4.4(KitKat) from 5.0(Lollipop)

Sadly I couldn't get any real devices so I have to work with an emulator.

My app is heavily based on user's location so the main testing must be target the location changing feature.

I try to use location simulation with the official Google Android Emulator. (x86)

I have made a 4.4 Emulator and is working fine, my app works fine but when I try to send locations via the Extended control panel nothing happens.

If I load a GPX file the locations appear on the table of the extended control panel inside the GPS data playback but the device does not get any locations.

enter image description here

I fill the lat and longitude click on "SEND" but nothing happens.

I have also tried to simulate location changing from the Android Device Monitor's "Emulator Control" tab

The "Send" button is not clickable at all, the long and lat fields are disabled and I cannot fill anything. The "GPX" and "KML" tabs are also disabled.

enter image description here

I have also tried to use the Gps Emulator plugin as the following:

enter image description here

The progress bar do increases, so not like the first 2 methods I have tried this is finally looks like actually doing something but the emulator still not getting the location changes. Not at all.

I have tried a fourth method via command line:

telnet localhost 5554

But I have Connection refused error message.

So I cannot try to send locations via:

geo fix <longitude value> <latitude value>

(Telnet is enabled on my Windows)

Baron answered 7/7, 2016 at 13:54 Comment(3)
What's your emulator version? Older version had a bug if a system locale where decimal separator was set to comma. It has to be fixed in the latest, 25.1.7, versionOverturf
a simple emulator restart did the job for me (long click on shutdown button and select restart)Vitia
I didn't know about the Gps Emulator plugin in Android Studio. Thanks for letting me know about that.Duce
R
13

I had the same problem with the SDK Tools version 25.1.7. I've updated them to 25.2 rc1 and it now works.

Beware that you cannot install the RC version from Android Studio. You have to launch the separate Android SDK Manager to see it.

Android SDk Manager with RC android SDK tools

Relaunch the emulator and check that you are indeed using the latest version in the Help/About screen of the Extended Controls windows.

Extended controls window

Raskin answered 18/7, 2016 at 9:28 Comment(7)
Though I am using 25.2.2-3098464 with Android N, I am not getting the lock in the emulator. Any idea why its not working?Birthday
To begin with, its not even getting location lock. i.e LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, listener); is not sending any location updatesBirthday
I have been trying to get this to work forever, I have the newest version:25.2.2-3098464, if I plug a real phone in, it gets locationUpdates, however with emulator nothing works. I have used the resolutionForResult method and everything returns success so I am at a loss.Kimball
Any help here? I am using Emulator version: 25.2.2-3098464 running on 6.0 (Marshmallow) - API 23 (Rev 1) but still can't get location to work :(Rainer
Not working with build tools version 25.2.3-3470232. How you were able to get this working with 25.2 rc1? I don't see any workaround also.Chaulmoogra
26.0.1 Tools, still not working. But my app indeed setting for the low battery use (works flawlessly on the phone).Cleek
26.03 - Still not working. Everything looks like it should be working. GPX can play, send button can be pressed, but app gets no location update.Samekh
C
185

I had the same problem, but I managed to fix it.

Run Google Maps and accept confirmations at least once until you see the map. Do not forget to set your location setting to ON/High accuracy, as shown in the screenshot below.

Google Maps Settings

Continuum answered 14/6, 2017 at 22:24 Comment(11)
This should be the accepted answer. I'm running an Android 8.0 emulator, latest version and I couldn't get the location to send to the device until I set High Accuracy in Settings.Marchelle
Agreed, this should be the accepted answer. I got no location data until I set the phone to GPS mode Only and then turned on High accuracy again. It asked me to agree and once I accepted, it was reporting the data as expected.Ferricyanide
This worked for me, with one additional step. Once I had Google Maps up and running, my location was not shown. I needed to go to the Extended Controls menu in the emulator, into the location section and click send. I also updated my location there to be at my home location, just because.Nubianubian
Wow - I was the first one to comment that this should be the accepted answer. 1.5 years later I forgot how to fix this and wasted 15 minutes trying to figure it out again, when accepting Google Maps terms is what fixed it again. Please make this the accepted answer!Marchelle
Followed everything above and it was still not working... I actually had to set my location settings to "Device Only"... and it worked! Oddly enough, I then toggled back to High Accuracy and it worked... until I restarted my emulator. At that point I had to set again to Device Only. I tried looking thru the logs and didnt see anything obvious, so I'm guessing that there is something being triggered.Orphism
This answer works, but fails to explain why it works. sidenote: There's no longer a "High Accuracy" and "Battery Saving" mode in Location settings for Android 9Raasch
making location as "High Accuracy" helps me.Densitometer
This is just a temporary solution. This isn't updating continuously if I am driving on a route from the emulator extended controls.Ranket
yes, definitely works after granting all permissions to Google Maps...Demonetize
Why is this necessary?Phenol
2024 and this worked for me!Sluiter
H
18

Using OS X and Android Studio, had the same problem and what worked for me was: going to the actual phone (emulator) Settings, Location, and turning off the location and turning it back on. Tested again, and started working.

I think it doesn't matter that much, but the Emulator version: 26.0.3-3965150.

Hanrahan answered 15/6, 2017 at 19:49 Comment(2)
High accuracy setting, on/off and then start maps, will enable GPSCordage
Thank you. You saved me a lot of time!Orola
R
13

I had the same problem with the SDK Tools version 25.1.7. I've updated them to 25.2 rc1 and it now works.

Beware that you cannot install the RC version from Android Studio. You have to launch the separate Android SDK Manager to see it.

Android SDk Manager with RC android SDK tools

Relaunch the emulator and check that you are indeed using the latest version in the Help/About screen of the Extended Controls windows.

Extended controls window

Raskin answered 18/7, 2016 at 9:28 Comment(7)
Though I am using 25.2.2-3098464 with Android N, I am not getting the lock in the emulator. Any idea why its not working?Birthday
To begin with, its not even getting location lock. i.e LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, listener); is not sending any location updatesBirthday
I have been trying to get this to work forever, I have the newest version:25.2.2-3098464, if I plug a real phone in, it gets locationUpdates, however with emulator nothing works. I have used the resolutionForResult method and everything returns success so I am at a loss.Kimball
Any help here? I am using Emulator version: 25.2.2-3098464 running on 6.0 (Marshmallow) - API 23 (Rev 1) but still can't get location to work :(Rainer
Not working with build tools version 25.2.3-3470232. How you were able to get this working with 25.2 rc1? I don't see any workaround also.Chaulmoogra
26.0.1 Tools, still not working. But my app indeed setting for the low battery use (works flawlessly on the phone).Cleek
26.03 - Still not working. Everything looks like it should be working. GPX can play, send button can be pressed, but app gets no location update.Samekh
L
8

In my case, the reason was location settings in phone settings set on "Battery saving". Switched it to "High accuracy" and it worked.

Ligon answered 26/3, 2017 at 10:15 Comment(0)
M
7

For me, just opening Goggle maps and skip configuration worked. Started on the default location and then changed to the location that I configured it

Info:

Device emulated: Pixel 3A

Emulator version: 30.0.12-6466327

Android version: 10.0 (Q) - API 29

Mensch answered 12/7, 2020 at 1:28 Comment(0)
V
5

a simple emulator restart did the job for me (long click on shutdown button and select restart)

Vitia answered 18/10, 2018 at 10:45 Comment(0)
I
4

On one Android emulator this answer worked, and on the other it also took a restart using the simulator Power button.

Image

Icosahedron answered 4/3, 2020 at 17:34 Comment(0)
D
3

enter image description here

I had to set the location to Device Only on the emulator for it to work. Sometimes have to switch between modes. Device only forces the use of GPS only and not WiFi, Bluetooth, etc.

Dashed answered 28/3, 2018 at 11:40 Comment(0)
R
3

emulator users:

if you are trying to passing longitude and latitude values from extended controller you have to add this code in your MainActivity.

String LOCATION_PROVIDER = LocationManager.GPS_PROVIDER;

in AndroidManifest

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Roderick answered 25/9, 2019 at 6:46 Comment(2)
Strange thing: it worked for me once, then it just stopped working as before. Why is that? I tried restarting my app which tracks my location but it doesn't update at all..Elzaelzevir
Doesn't make any sense. Why should you set a string you never use? Permission "INTERNET" is not used for location. I think Adam Varhegyi already knew that he had to set ACCESS_FINE_LOCATION.Whim
D
0

I had the same problem with the FusedLocationProviderClient I resolved it by adding code to the addOnFailureListener in the SettingsClient object which exposes a ResolvableApiException object. I simply made a call to:

(resolvableApiException as ResolvableApiException).startResolutionForResult(mainActivity, 6)

This showed a popup with which I responded 'OK' and the AVD issue was resolved.

I've made a project that you can download from bitbucket. https://bitbucket.org/warwick/avd-location-fix/src/master/

The repo contains a zip file 'AvdLocationFix.zip'. This file contains an Android project. Just open it in Android Studio and run it on the AVD that is causing the problem. After running the app you may have to disable and re-enable the location in the AVD for it to work properly.

Hope this helps.

Duce answered 20/5, 2020 at 9:6 Comment(0)
F
0

I fixed my issue by deleting the Android image and installing latest Android system from AVD manager. After that I used a new device using that system which eventually made things work for me. Android Image System Installed Finishing up Hopefully this helps someone.

Frangipane answered 5/12, 2021 at 2:23 Comment(0)
L
-1

I also had this issue, I took over a skeleton project from someone else and could not get the emulator to pick up the GPS location.

In my case the issue was the LocationManager chosen by default in the project crested in Android Studio, which was using Network and not GPS

Lottie answered 21/2, 2018 at 13:9 Comment(0)
Y
-1

Last ditch effort: Wipe the emulator data and try again. This is what fixed it for me after Android Studio did an AVD update.

Yarmouth answered 28/9, 2020 at 16:57 Comment(0)
N
-2

I have also tried to simulate location changing from the Android Device Monitor's "Emulator Control" tab The "Send" button is not clickable at all, the long and lat fields are disabled and I cannot fill anything. The "GPX" and "KML" tabs are also disabled.

I noticed the same thing, but then I looked in the extended menu on the emulator itself. You can update the location through the emulator menu. enter image description here

Nubianubian answered 22/12, 2016 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.