android gps 卫星数据格式,Gps开发实战——卫星数量获取
衛(wèi)星數(shù)量有兩種:衛(wèi)星總數(shù)(all),和已校準(zhǔn)衛(wèi)星數(shù)(fixed);
衛(wèi)星數(shù)量來源于gps定位數(shù)據(jù),gps數(shù)據(jù)來源又有兩種:內(nèi)置gps和外接gps設(shè)備。
一、內(nèi)置gps數(shù)據(jù)來源的計(jì)算方式
開始啟用內(nèi)置gps時(shí),通過LocationManager.addGpsStatusListener()api,監(jiān)聽gps狀態(tài),在監(jiān)聽的回調(diào)中計(jì)算衛(wèi)星數(shù)量,代碼:
mGpsStatusCallback = new GpsStatus.Listener() {
@Override
public void onGpsStatusChanged(int event) {
if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
//衛(wèi)星狀態(tài)改變
fetchCurGpsStatus();
}
}
};
mService = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
mService.addGpsStatusListener(mGpsStatusCallback);
注冊(cè)監(jiān)聽永遠(yuǎn)要記得在不再需要時(shí)解除監(jiān)聽,當(dāng)關(guān)閉內(nèi)置gps時(shí),移除監(jiān)聽:
mService.removeGpsStatusListener(mGpsStatusCallback);
衛(wèi)星狀態(tài)改變時(shí),首先獲取GpsStatus,通過如下方式處理:
1,通過GpsStatus獲取到衛(wèi)星對(duì)象(GpsSatellite)列表,包含了當(dāng)前能搜到的所有衛(wèi)星;
2,GpsSatellite對(duì)象中有mUsedInFix字段標(biāo)記其是否是參與定位校準(zhǔn)。遍歷上述列表,統(tǒng)計(jì)已校準(zhǔn)的衛(wèi)星數(shù)fixedSatellites,發(fā)布消息,通知衛(wèi)星數(shù)量改變;
3,基于3衛(wèi)星定位的最低要求,判斷fixedSatellites是否是3顆以上,如果不是,那么認(rèn)為當(dāng)前定位失敗。
大致代碼如下:
private void fetchCurGpsStatus() {
GpsStatus mStatus = mService.getGpsStatus(null);
//獲取衛(wèi)星顆數(shù)的默認(rèn)最大值
int maxSatellites = mStatus.getMaxSatellites();
//創(chuàng)建一個(gè)迭代器保存所有衛(wèi)星
Iterator iters = mStatus.getSatellites().iterator();
//衛(wèi)星數(shù)
int count = 0;
if (iters != null) {
while (iters.hasNext() && count <= maxSatellites) {
GpsSatellite s = iters.next();
if (s.usedInFix()) {
count++;
}
}
}
if (count < 3) {
//定位失敗
} else {
//定位成功
}
}
二、外接gps設(shè)備據(jù)來源的計(jì)算方式(藍(lán)牙gps)
標(biāo)準(zhǔn)nmea格式的gps數(shù)據(jù)中GPGGA格式的數(shù)據(jù)會(huì)包含Number of satellites being tracked(追蹤到的衛(wèi)星數(shù)量)即為目標(biāo)數(shù)據(jù)(fixed)。
/* $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 */
Where:
GGA Global Positioning System Fix Data
123519 Fix taken at 12:35:19 UTC
4807.038,N Latitude 48 deg 07.038' N
01131.000,E Longitude 11 deg 31.000' E
1 Fix quality:
08 Number of satellites being tracked
0.9 Horizontal dilution of position
545.4,M Altitude, Meters, above mean sea level
46.9,M Height of geoid (mean sea level) above WGS84
ellipsoid
(empty field) time in seconds since last DGPS update
(empty field) DGPS station ID number
*47 the checksum data, always begins with *
GPGSV格式的數(shù)據(jù)中會(huì)包含Number of satellites in view(所有可及的衛(wèi)星數(shù)),是可搜到的所有衛(wèi)星數(shù)(all)。
/* $GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75 */
Where:
GSV Satellites in view
2 Number of sentences for full data
1 sentence 1 of 2
08 Number of satellites in view
01 Satellite PRN number
40 Elevation, degrees
083 Azimuth, degrees
46 SNR - higher is better
for up to 4 satellites per sentence
*75 the checksum data, always begins with *
Sometimes got $GPGSV,1,1,00*75 when just started
or inside building.
總結(jié)
以上是生活随笔為你收集整理的android gps 卫星数据格式,Gps开发实战——卫星数量获取的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 命名实体识别python_命名实体识别的
- 下一篇: GPS卫星定位接收器的NMEA协议解析