我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
当前回答
在Linux系统中,通信端口被阻塞。导航终端到android SDK中的platform-tools文件夹,并启动以下命令:
./adb -s #{device_name} emu geo fix #{longitude} #{latitude}
其他回答
还不能评论,所以更新@ectomorphs回答在这里,当telneting现在需要一个认证令牌。在linux中,它在/home/username/.emulator_console_auth_token下
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import telnetlib
from time import sleep
import random
FILE = open('/home/username/.emulator_console_auth_token', 'r')
AUTH_TOKEN = FILE.read()
FILE.close()
HOST = "127.0.0.1"
PORT = 5554
TIMEOUT = 10
LAT_SRC = 52.5243700
LNG_SRC = 13.4105300
LAT_DST = 53.5753200
LNG_DST = 10.0153400
SECONDS = 120
LAT_MAX_STEP = ((max(LAT_DST, LAT_SRC) - min(LAT_DST, LAT_SRC)) / SECONDS) * 2
LNG_MAX_STEP = ((max(LNG_DST, LNG_SRC) - min(LNG_DST, LNG_SRC)) / SECONDS) * 2
DIRECTION_LAT = 1 if LAT_DST - LAT_SRC > 0 else -1
DIRECTION_LNG = 1 if LNG_DST - LNG_SRC > 0 else -1
lat = LAT_SRC
lng = LNG_SRC
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
tn.set_debuglevel(9)
tn.read_until("OK", 5)
tn.write("auth {0}\n".format(AUTH_TOKEN))
tn.read_until("OK", 5)
tn.read_until("OK", 5)
tn.write("geo fix {0} {1}\n".format(LNG_SRC, LAT_SRC))
#tn.write("exit\n")
for i in range(SECONDS):
lat += round(random.uniform(0, LAT_MAX_STEP), 7) * DIRECTION_LAT
lng += round(random.uniform(0, LNG_MAX_STEP), 7) * DIRECTION_LNG
#tn.read_until("OK", 5)
tn.write("geo fix {0} {1}\n".format(lng, lat))
#tn.write("exit\n")
sleep(1)
tn.write("geo fix {0} {1}\n".format(LNG_DST, LAT_DST))
tn.write("exit\n")
print tn.read_all()
在shell脚本中,可以像这样设置坐标
#!/usr/bin/env bash
export ATOKEN=`cat ~/.emulator_console_auth_token`
echo -ne "auth $ATOKEN\ngeo fix -99.133333 19.43333 2202\n" | nc localhost 5554
这里没有人提到模拟器本身的内置解决方案,所以对于未来的访问者,我想用视觉效果来分享它。
首先,运行你的Android模拟器,点击菜单按钮(3点)如下所示:
然后在左侧窗格中,选择Location并根据需要更改坐标。按下发送按钮后,更改将立即生效(建议大家打开谷歌Maps以便更好地理解)。
Android Studio版本:2.3.3
此外,为了使不同的位置实时到达应用程序,可以使用GPX文件。从谷歌地图方向创建这个文件非常简单:
进入谷歌地图,选择一个位置,然后按“方向”进入第二个位置。 创建路由后,从浏览器复制一个链接 访问这个网站:https://mapstogpx.com,并将链接粘贴到“Let's Go”框 按下“Let's Go”键,即可下载GPX文件
使用“加载GPS/KML”按钮将创建的文件加载到模拟器中,选择速度,并按底部的绿色播放按钮。如下图所示,位置将实时发送。
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.
我正在寻找一种更好的方法来设置模拟器的GPS坐标,而不是使用地理固定和手动确定特定的纬度和经度坐标。
找不到任何东西,我把一个小程序,使用GWT和谷歌Maps API来启动一个基于浏览器的地图工具,在模拟器中设置GPS位置:
android-gps-emulator
希望它能帮助那些无疑也会遇到这个困难/问题的人。
我试图通过adb为许多点设置地理定位,但无法让我的应用程序看到任何GPS数据。但当我尝试打开DDMS时,选择我的应用程序的进程并通过模拟器控制选项卡发送坐标,它马上就工作了。