我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
当前回答
对于新的模拟器:
http://developer.android.com/tools/devices/emulator.html#extended
基本上,点击模拟器控件中的三个点按钮(模拟器的右侧),它将打开一个菜单,允许你控制模拟器,包括位置
其他回答
如果你正在使用eclipse,然后使用模拟器控制器,你可以手动设置纬度和经度,并在模拟器中运行基于地图的应用程序
我正在寻找一种更好的方法来设置模拟器的GPS坐标,而不是使用地理固定和手动确定特定的纬度和经度坐标。
找不到任何东西,我把一个小程序,使用GWT和谷歌Maps API来启动一个基于浏览器的地图工具,在模拟器中设置GPS位置:
android-gps-emulator
希望它能帮助那些无疑也会遇到这个困难/问题的人。
我写了一个python脚本,通过telnet将gps位置推到模拟器。它定义了源位置和目标位置。还有一个时间偏移,它可以让你控制坐标将被推送到设备的时间。一个位置每秒推送一次。
在下面的例子中,脚本在120秒内从柏林转移到汉堡。每秒一步/gps定位,随机距离。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import telnetlib
from time import sleep
import random
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("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()
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.
如果上述解决方案不奏效。试试这个:
在你的android manifest .xml中,在应用程序标记之外添加以下两个链接,当然是在你的manifest标记中
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>