Quantcast
Channel: CSDN博客移动开发推荐文章
Viewing all articles
Browse latest Browse all 5930

android location 数据标准输出,原始mnea输出和GpsStatus卫星状态的变化

$
0
0
android LocationListener数据标准输出,原始NmeaListener输出和卫星状态的变化。标准输出就是由系统api已经封装好进行输出经纬度等等。原始数据有很多也可以解出来经纬度,解状态,卫星状态颗数。什么卫星组成,信噪比等等。卫星状态一般是信噪比以及卫星编号,方位角,高度角等

本文博客代码:http://download.csdn.net/download/qq_16064871/9965795

1,界面的简单显示


2,示例代码

初始化locationmanage

		if(mLocationManager == null)
		mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
		if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
			mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0, 0, mLocationListener); 
			mLocationManager.addNmeaListener(mNmeaListener);
			mLocationManager.addGpsStatusListener(mStatusChanged);
		}


有系统解析出来的标准输出

	LocationListener mLocationListener = new LocationListener() {
		@TargetApi(17)
		@Override
		public void onLocationChanged(Location mlocal) {
			if(mlocal == null) return;
			String strResult = "getAccuracy:" + mlocal.getAccuracy() + "\r\n"
					+ "getAltitude:" + mlocal.getAltitude() + "\r\n"
					+ "getBearing:" + mlocal.getBearing() + "\r\n"
					+ "getElapsedRealtimeNanos:" + String.valueOf(mlocal.getElapsedRealtimeNanos()) + "\r\n"
					+ "getLatitude:" + mlocal.getLatitude() + "\r\n"
					+ "getLongitude:" + mlocal.getLongitude() + "\r\n"
					+ "getProvider:" + mlocal.getProvider()+ "\r\n"
					+ "getSpeed:" + mlocal.getSpeed() + "\r\n"
					+ "getTime:" + mlocal.getTime() + "\r\n";
			Log.i("Show", strResult);
			if (mTextView != null) {
				mTextView.setText(strResult);
				}
		}

		@Override
		public void onProviderDisabled(String arg0) {
		}

		@Override
		public void onProviderEnabled(String arg0) {
		}

		@Override
		public void onStatusChanged(String provider, int event, Bundle extras) {
			
		}
	};

NmeaListener 原始的数据数据,需要自已去解析。解析可按照: GPS NMEA-0183标准详解(常用的精度以及经纬度坐标)

当然在这里你可以获取其他数据进行解析。记得打开手机的gps定位哦。

例如:获取gga数据,进行解析解状态,当然里面也有经纬度等

	//$GPGGA,072024.0,2307.582054,N,11321.928800,E,1,07,0.7,45.2,M,-4.0,M,,*76
	//原始数据监听
	NmeaListener mNmeaListener = new NmeaListener() {
		@Override
		public void onNmeaReceived(long arg0, String arg1) {
				if(arg1.contains("GPGGA")){
					Log.i("Show",arg1);
					String[] result = arg1.split(",");
					if(result != null && result.length >= 11){
						mTextView2.setText(GetnSolutionState(Integer.parseInt(result[6])));
					}
				}
				
		}
	};
	
    private String GetnSolutionState(int nType) {
        String strSolutionState = "";
        switch (nType) {
            case 0:
                strSolutionState = "无效解";
                break;
            case 1:
                strSolutionState = "单点解";
                break;
            case 2:
                strSolutionState = "差分解";
                break;
            case 4:
                strSolutionState = "固定解";
                break;
            case 5:
                strSolutionState = "浮点解";
                break;
            default:
                strSolutionState = "" + nType;
                break;
        }
        return strSolutionState;
    }

记得:销毁和及时启动

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
			mLocationManager.removeNmeaListener(mNmeaListener);
			mLocationManager.removeUpdates(mLocationListener);
			mLocationManager.removeGpsStatusListener(mStatusChanged);
		}
	}
	
	@Override
	protected void onResume() {
		getLocation();
		super.onDestroy();
	}

权限如下

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

location相关博文

android 模拟位置信息Location使用示例





作者:qq_16064871 发表于2017/9/6 22:27:59 原文链接
阅读:186 评论:0 查看评论

Viewing all articles
Browse latest Browse all 5930

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>