我有一个项目需要将位置设置为印度,但是在我的模拟器上无法获取位置。
- 我需要将位置设置为印度
当我在模拟器上使用谷歌地图时,它显示的当前位置在海洋中央。
API level I am using is 27.
Emulator I use is Nexus 5x.
如何在模拟器和手动方式中获取当前位置。
我尝试编辑模拟器中的位置,尝试提供纬度和经度,但它不起作用。
我有一个项目需要将位置设置为印度,但是在我的模拟器上无法获取位置。
当我在模拟器上使用谷歌地图时,它显示的当前位置在海洋中央。
API level I am using is 27.
Emulator I use is Nexus 5x.
如何在模拟器和手动方式中获取当前位置。
我尝试编辑模拟器中的位置,尝试提供纬度和经度,但它不起作用。
您可以使用命令提示符或ADB设置位置。
在AndroidManifest.xml中设置权限:
查找Android模拟器的正确本地端口:
$ adb devices
List of devices attached
emulator-5554 device
$ 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
手动设置首选位置:您可以使用geo fix命令设置位置:
geo fix $longitude $latitude
例如
geo fix 2.169919 41.387917
OK
另外一种简单的方式
从Android Studio中打开Android设备监视器。
选择模拟器。
选择模拟器控制。
在模拟器控制中选择位置控制。
选择手动。
在那里输入您的经度和纬度。
我通过清除模拟器的数据并重新启动解决了这个问题。
$ adb devices
List of devices attached
emulator-5554 device
$ 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
geo fix $longitude $latitude
geo fix 2.169919 41.387917
OK
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
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
将 Android 位置管理器的强制设置为 true。像这样 "position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.low, forceAndroidLocationManager: true);" 然后您就可以在模拟器上获取位置了。