Adam Varhegyi
Adam Varhegyi

Reputation: 9894

Emulator's Location simulation not working

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)

Upvotes: 82

Views: 116205

Answers (16)

tir38
tir38

Reputation: 10421

I only got this working after switching to an emulator with Play Services. None of the AOSP emulators worked.

Upvotes: 0

irwanto
irwanto

Reputation: 1

just simple, shutting down your emulator then start again with cold boot. it's worked. 2024

Upvotes: 0

idan hav
idan hav

Reputation: 181

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

Image

Upvotes: 4

MK.
MK.

Reputation: 832

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.

Upvotes: 0

user2288580
user2288580

Reputation: 2258

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.

Upvotes: 0

Sludge
Sludge

Reputation: 7395

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

Upvotes: -1

Thiago Cavalcanti
Thiago Cavalcanti

Reputation: 523

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

Upvotes: 7

HeshanHH
HeshanHH

Reputation: 703

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"/>

Upvotes: 3

Cosmin Badulescu
Cosmin Badulescu

Reputation: 235

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

Upvotes: 5

Meanman
Meanman

Reputation: 1544

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.

Upvotes: 3

Klunk
Klunk

Reputation: 825

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

Upvotes: -1

Alejandro Pablo Tkachuk
Alejandro Pablo Tkachuk

Reputation: 2256

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.

Upvotes: 20

Emre Kilinc Arslan
Emre Kilinc Arslan

Reputation: 2189

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

Upvotes: 186

a1eksandre
a1eksandre

Reputation: 416

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

Upvotes: 8

Eric Engel
Eric Engel

Reputation: 303

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

Upvotes: -2

fstephany
fstephany

Reputation: 2354

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

Upvotes: 13

Related Questions