Android的 - 在模拟器误差测试GPS [英] Android - Error Test GPS on Emulator
问题描述
我想在我的Android模拟器测试GPS,但我觉得我的应用程序有错误意外停止当我尝试在模拟器中运行它。
i wanna test GPS on my android emulator but i find my apps has Error "Stopped Unexpectedly" when i try to run its on emulator.
下面某种我codeS的 AndroidManifest.xml中
here some sort of my codes AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
和main.java
and main.java
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location){
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if(location != null){
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
}else{
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is: \n" + latLongString);
}
导入我的main.java
import on my main.java
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
你能告诉我,为什么我的应用程序得到错误意外停止当我尝试对我的模拟器上运行它?
would you tell me why my apps getting error "stopped unexpectedly" when i try to run its on my emulator ?
感谢您帮助我:)
这是跟踪误差 使用DDMS设置长和LAT这个我已经: 长:112.8010100 纬度:-7.2950700
Error from tracing : "java.lang.NullPointerException" i have been using DDMS to set long and lat to this: long: 112.8010100 lat : -7.2950700
推荐答案
您可以在仿真模拟的位置
在开发应用程序时,你一定要考好怎么 模型获取用户位置的作品。这是最容易做的 使用一个真正的Android系统 设备。但是,如果你没有设备,你仍然可以测试你的 基于位置的功能被嘲笑的位置数据在Android模拟器。 有三种不同的方式来发送您的应用程序的模拟位置数据: 在模拟器控制台使用Eclipse,DDMS,或地理的命令。
As you develop your application, you'll certainly need to test how well your model for obtaining user location works. This is most easily done using a real Android-powered device. If, however, you don't have a device, you can still test your location-based features by mocking location data in the Android emulator. There are three different ways to send your application mock location data: using Eclipse, DDMS, or the "geo" command in the emulator console.
注:提供模拟位置数据被注入GPS定位数据, 所以你必须请求,以便模拟从GPS_PROVIDER位置更新 位置数据。
Note: Providing mock location data is injected as GPS location data, so you must request location updates from GPS_PROVIDER in order for mock location data to work.
使用Eclipse
选择窗口>显示视图>其它>仿真器控制。
Select Window > Show View > Other > Emulator Control.
在仿真器控制面板,输入GPS坐标 在位置控制作为单独的纬度/经度坐标, 与GPX文件路径的播放,或KML文件 多个地方的痕迹。 (请确保您有一个设备选择 在设备面板可从窗口>显示视图>其它>设备。)
In the Emulator Control panel, enter GPS coordinates under Location Controls as individual lat/long coordinates, with a GPX file for route playback, or a KML file for multiple place marks. (Be sure that you have a device selected in the Devices panel—available from Window > Show View > Other > Devices.)
使用DDMS
随着DDMS工具,你可以模拟位置数据的几种不同的方式:
With the DDMS tool, you can simulate location data a few different ways:
手动发送单独的经度/纬度坐标到设备。 使用描述用于回放给设备的路线的GPX文件。 使用一个KML文件描述个别的地方标记为测序 播放设备。 有关使用DDMS欺骗位置数据的详细信息,请参阅使用DDMS。
Manually send individual longitude/latitude coordinates to the device. Use a GPX file describing a route for playback to the device. Use a KML file describing individual place marks for sequenced playback to the device. For more information on using DDMS to spoof location data, see Using DDMS.
在模拟器控制台使用地理命令
要在命令行发送模拟位置数据:
To send mock location data from the command line:
在Android模拟器启动应用程序,并打开一个终端/主机 在你的SDK的/ tools目录中。 连接到模拟器控制台: 远程登录本地主机 发送位置数据: 地缘固定到发一组固定的地理定位。 这个命令接受一个经度和纬度十进制度, 一个可选的海拔在米。例如: 地缘修复-121.45356 46.51119 4392 地理NMEA发送NMEA 0183句。 此命令接受类型的单一NMEA一句'$ GPGGA'(修正数据)或 '$ GPRMC'(传输中的数据)。例如: 地缘NMEA $ GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E * 62 有关如何连接到模拟器控制台的信息,请参阅使用 仿真器控制台。
Launch your application in the Android emulator and open a terminal/console in your SDK's /tools directory. Connect to the emulator console: telnet localhost Send the location data: geo fix to send a fixed geo-location. This command accepts a longitude and latitude in decimal degrees, and an optional altitude in meters. For example: geo fix -121.45356 46.51119 4392 geo nmea to send an NMEA 0183 sentence. This command accepts a single NMEA sentence of type '$GPGGA' (fix data) or '$GPRMC' (transit data). For example: geo nmea $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62 For information about how to connect to the emulator console, see Using the Emulator Console.
这篇关于Android的 - 在模拟器误差测试GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!