无法使基于NMEA文件的模拟位置提供程序工作

时间:2011-07-23 13:29:27

标签: android mocking gps location

我仍在努力完成我的第一次Android挑战(对我自己;))我现在处于一个我想测试/调试某些基于位置的功能的位置,但我根本无法让它工作......

这是我订阅导航更新的代码:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// We create the mock location provider
try {
    locationManager.addTestProvider("mockgps", false, false,
            false, false, true, true, true, 0, 5);
} catch (IllegalArgumentException e) {
    Log.w(getString(R.string.debug_tag),String.format("%s: mockgps was already created...", this.getClass().getSimpleName()));;
}

// Debugging we have the providers we need
List<String> providers = locationManager.getAllProviders();
Log.v(getString(R.string.debug_tag),String.format("%s: location provider ={%s}...", this.getClass().getSimpleName(), providers));

locationManager.requestLocationUpdates("mockgps", 100L, 0, locationListener);

// Some code removed
locationManager.setTestProviderEnabled("mockgps", true);

这是我推送到 / data / misc / location / mockgps / nmea

的NMEA文件
geo nmea $GPGGA,101205.0,4341.421828,N,00355.725347,E,1,09,0.9,80.1,M,49.0,M,,*6B
geo nmea $GPRMC,101205.0,A,4341.421828,N,00355.725347,E,0.0,,210711,,,A*47
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101206.0,4341.421827,N,00355.725350,E,1,09,0.9,80.1,M,49.0,M,,*61
geo nmea $GPRMC,101206.0,A,4341.421827,N,00355.725350,E,0.0,,210711,,,A*4D
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101207.0,4341.421825,N,00355.725354,E,1,09,0.9,80.1,M,49.0,M,,*66
geo nmea $GPRMC,101207.0,A,4341.421825,N,00355.725354,E,0.0,,210711,,,A*4A
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101208.0,4341.421825,N,00355.725354,E,1,09,0.9,80.1,M,49.0,M,,*69
geo nmea $GPRMC,101208.0,A,4341.421825,N,00355.725354,E,0.0,,210711,,,A*45
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101209.0,4341.420608,N,00355.725766,E,1,09,0.9,79.9,M,49.0,M,,*63
geo nmea $GPRMC,101209.0,A,4341.420608,N,00355.725766,E,0.0,,210711,,,A*41
geo nmea $GPGGA,101210.0,4341.420878,N,00355.726052,E,1,09,1.1,80.0,M,49.0,M,,*67
geo nmea $GPRMC,101210.0,A,4341.420878,N,00355.726052,E,0.0,,210711,,,A*43
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.8,1.1,1.4*34
geo nmea $GPGGA,101211.0,4341.421209,N,00355.726245,E,1,09,0.9,78.9,M,49.0,M,,*68
geo nmea $GPRMC,101211.0,A,4341.421209,N,00355.726245,E,0.0,,210711,,,A*4B
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101212.0,4341.421025,N,00355.726918,E,1,09,1.0,78.3,M,49.0,M,,*66
geo nmea $GPRMC,101212.0,A,4341.421025,N,00355.726918,E,0.0,,210711,,,A*47
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,1.0,1.4*3A
geo nmea $GPGGA,101213.0,4341.421078,N,00355.726329,E,1,09,0.9,78.7,M,49.0,M,,*6B
geo nmea $GPRMC,101213.0,A,4341.421078,N,00355.726329,E,0.0,,210711,,,A*46
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101214.0,4341.420836,N,00355.726263,E,1,09,1.1,79.3,M,49.0,M,,*6C
geo nmea $GPRMC,101214.0,A,4341.420836,N,00355.726263,E,0.0,,210711,,,A*4D
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.8,1.1,1.4*34
geo nmea $GPGGA,101215.0,4341.420796,N,00355.726174,E,1,09,1.1,79.7,M,49.0,M,,*69
geo nmea $GPRMC,101215.0,A,4341.420796,N,00355.726174,E,0.0,,210711,,,A*4C
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.8,1.1,1.4*34
geo nmea $GPGGA,101216.0,4341.420774,N,00355.725884,E,1,06,1.1,80.1,M,49.0,M,,*6C
geo nmea $GPVTG,nan,T,nan,M,0.0,N,0.0,K,A*23
geo nmea $GPRMC,101216.0,A,4341.420774,N,00355.725884,E,0.0,,210711,,,A*46
geo nmea $GPGSA,A,3,09,12,15,18,22,27,,,,,,,1.8,1.1,1.4*3C
geo nmea $GPGGA,101217.0,4341.420783,N,00355.725775,E,1,06,1.1,80.4,M,49.0,M,,*61
geo nmea $GPRMC,101217.0,A,4341.420783,N,00355.725775,E,0.0,,210711,,,A*4E
geo nmea $GPGSA,A,3,09,12,15,18,22,27,,,,,,,1.8,1.1,1.4*3C
geo nmea $GPGSV,4,1,16,09,48,291,35,18,27,291,35,15,80,212,33,22,08,322,28*7E
geo nmea $GPGSV,4,2,16,12,20,217,27,27,65,313,24,26,45,133,24,17,31,092,21*77
geo nmea $GPGSV,4,3,16,32,,,,31,,,,30,,,,29,,,*72
geo nmea $GPGSV,4,4,16,25,,,,24,,,,23,,,,21,,,*7D
geo nmea $GPGGA,101218.0,4341.420815,N,00355.725879,E,1,06,1.1,80.5,M,49.0,M,,*6C
geo nmea $GPRMC,101218.0,A,4341.420815,N,00355.725879,E,0.0,,210711,,,A*42
geo nmea $GPGSA,A,3,09,12,15,18,22,27,,,,,,,1.8,1.1,1.4*3C

我确实在监听器中有相当全面的日志记录,绝对没有发生...... 我没有获得GPS状态更新,也没有任何位置更新...

您将非常感谢您的帮助。这是一个真正的痛苦,因为我甚至无法想到必须在真实手机上进行任何单一测试的麻烦(除了砖块的风险,我只有自己的“真正的”手机)。

我仍然使用模拟器,我的测试设备是2.3.3。

对于记录,这里是监听器代码:

LocationListener locationListener = new LocationListener() {

    public void onLocationChanged(Location location) {
        // Called when a new location is found by the network location provider.
        Log.v(getString(R.string.debug_tag),String.format("%s: got new location (%s)",
                NavManager.class.getSimpleName(), location.toString()));
        if (currentLocation != null) {
            lastLocation = currentLocation;
            currentLocation = new Location(location);
        }

        if (navigation == null) {
            navigation = new Navigation();
        }

        navigation.setLocation(currentLocation);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        locProvider = provider;
        locProviderStatus = status;
        Log.v(getString(R.string.debug_tag),String.format("%s: location provider status changed (povider=\"%s\", status=%d)",
                NavManager.class.getSimpleName(), locProvider, locProviderStatus));
    }

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };   

2 个答案:

答案 0 :(得分:0)

您只需从DDMS透视图发送坐标即可测试代码,无需加载NMEA文件。对于坐标,高度,速度,跨度,strings等数据非常多。从该文件中提取的速度,航向,卫星数量,跟踪卫星。做简单的方法。提取所有这些字符串将花费你很多时间。

使用DDMS中的位置控制,您仍然可以发送一些模拟坐标,实际上您可以模拟同时发送相同NMEA文件的GPS设备,但使用比解析/提取所有字符串更简单。

请在此处查看提供NMEA文件http://aprs.gids.nl/nmea/

的信息

答案 1 :(得分:0)

模拟器中存在一个错误,因此NmeaListener onNmeaReceived(long timestamp,String nmea)从未收到任何内容。