我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
当前回答
在模拟中选择扩展控件。之后,您可以通过搜索或拖动映射到要设置的位置来设置模拟的位置。
最后点击SET LOCATION按钮保存。
其他回答
对于新的模拟器:
http://developer.android.com/tools/devices/emulator.html#extended
基本上,点击模拟器控件中的三个点按钮(模拟器的右侧),它将打开一个菜单,允许你控制模拟器,包括位置
把阿尔贝托·高纳的回答写在一行里
token=$(cat ~/.emulator_console_auth_token); cat <(echo -e "auth $token \n geo fix 96.0290791 16.9041016 \n exit") - | nc localhost 5554
5554是adb设备中显示的模拟器端口号。
如果亚行的emu能够发挥作用,情况会更好。
Dalvik Debug Monitor >选择模拟器>模拟器控制选项卡>位置控制。
DDMS——android_sdk/tools/ DDMS或android_sdk/tools/monitor
还不能评论,所以更新@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
请参见获取用户位置
请参阅提供模拟位置数据。你会找到解决方法的。