简体   繁体   English

Android - 模拟器上的错误测试GPS

[英]Android - Error Test GPS on Emulator

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. 我想在我的Android模拟器上测试GPS,但是当我尝试在模拟器上运行时,我发现我的应用程序有错误“意外停止”。

here some sort of my codes AndroidManifest.xml 这里有一些我的代码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" />

and main.java 和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);
}

import on my main.java 导入我的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 ? 你能告诉我为什么当我试图在我的模拟器上运行时,我的应用程序会出现错误“意外停止”吗?

thanks for helping me :) 谢谢你帮助我:)

Error from tracing : "java.lang.NullPointerException" i have been using DDMS to set long and lat to this: long: 112.8010100 lat : -7.2950700 跟踪错误:“java.lang.NullPointerException”我一直在使用DDMS设置long和lat到:long:112.8010100 lat:-7.2950700

You can mock the location in the emulator 您可以在模拟器中模拟位置

Providing Mock Location Data 提供模拟位置数据

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. 这是使用真正的Android设备最容易完成的。 If, however, you don't have a device, you can still test your location-based features by mocking location data in the Android emulator. 但是,如果您没有设备,则仍可以通过在Android模拟器中模拟位置数据来测试基于位置的功能。 There are three different ways to send your application mock location data: using Eclipse, DDMS, or the "geo" command in the emulator console. 发送应用程序模拟位置数据有三种不同的方法:在模拟器控制台中使用Eclipse,DDMS或“geo”命令。

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. 注意:提供模拟位置数据作为GPS位置数据注入,因此您必须从GPS_PROVIDER请求位置更新,以便模拟位置数据起作用。

Using Eclipse 使用Eclipse

Select Window > Show View > Other > Emulator Control. 选择Window> Show View> Other> Emulator Control。

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. 在“模拟器控制”面板中,在“位置控件”下输入GPS坐标作为单独的纬度/经度坐标,使用GPX文件进行路径回放,或输入多个位置标记的KML文件。 (Be sure that you have a device selected in the Devices panel—available from Window > Show View > Other > Devices.) (确保在“设备”面板中选择了一个设备 - 可从“窗口”>“显示视图”>“其他”>“设备”中获取。)

Using DDMS 使用DDMS

With the DDMS tool, you can simulate location data a few different ways: 使用DDMS工具,您可以通过几种不同的方式模拟位置数据:

Manually send individual longitude/latitude coordinates to the device. 手动将单独的经度/纬度坐标发送到设备。 Use a GPX file describing a route for playback to the device. 使用描述要回放到设备的路由的GPX文件。 Use a KML file describing individual place marks for sequenced playback to the device. 使用KML文件描述各个位置标记,以便对设备进行顺序回放。 For more information on using DDMS to spoof location data, see Using DDMS. 有关使用DDMS欺骗位置数据的更多信息,请参阅使用DDMS。

Using the "geo" command in the emulator console 在模拟器控制台中使用“geo”命令

To send mock location data from the command line: 要从命令行发送模拟位置数据:

Launch your application in the Android emulator and open a terminal/console in your SDK's /tools directory. 在Android模拟器中启动您的应用程序,并在SDK的/ tools目录中打开终端/控制台。 Connect to the emulator console: telnet localhost Send the location data: geo fix to send a fixed geo-location. 连接到模拟器控制台:telnet localhost发送位置数据:geo fix以发送固定的地理位置。 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. 例如:geo fix -121.45356 46.51119 4392 geo nmea发送NMEA 0183句子。 This command accepts a single NMEA sentence of type '$GPGGA' (fix data) or '$GPRMC' (transit data). 此命令接受单个“$ GPGGA”类型的NMEA语句(修复数据)或“$ GPRMC”(传输数据)。 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. 例如:geo nmea $ GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E * 62有关如何连接到仿真器控制台的信息,请参阅使用仿真器控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM