使用PHP實(shí)現(xiàn)NMEA0183協(xié)議中的GGA語句解析
NMEA0183協(xié)議是接收機(jī)輸出定位信息的通用標(biāo)準(zhǔn)之一,其中GGA語句包含了關(guān)鍵的時(shí)間、經(jīng)緯度、定位狀態(tài)等內(nèi)容。如何使用PHP實(shí)現(xiàn)該數(shù)解析功能,接下來由百恒物聯(lián)技術(shù)部工程師向大家介紹實(shí)現(xiàn)方法。
格式:
$GPGGA,134658.00,5106.9792,N,11402.3003,W,2,09,1.0,1048.47,M,-16.27,M,08,AAAA*60
Num
|
字段
|
具體內(nèi)容
|
格式
|
示例
|
1
|
$GPGGA
|
記錄頭
|
|
$GPGGA
|
2
|
utc
|
定位時(shí)間
|
hhmmss.ss
|
134658.00
|
3
|
lat
|
緯度
|
DDmm.mm
|
5106.9792
|
4
|
lat direction
|
緯度方向,北緯N或南緯S
|
|
N
|
5
|
lon
|
經(jīng)度
|
DDDmm.mm
|
11402.300
|
6
|
lon direction
|
經(jīng)度方向,東經(jīng)E或西經(jīng)W
|
|
W
|
7
|
quality
|
表示定位解的狀態(tài),常用有1=單點(diǎn)解,2=偽距差分解,4=RTK固定解,5=RTK浮點(diǎn)解
|
|
2
|
8
|
# sats
|
參與定位解算的衛(wèi)星數(shù)
|
|
09
|
9
|
hdop
|
水平精度因子
|
|
1.0
|
10
|
altitude
|
天線海拔高,相距于平均海水面
|
|
1048.47
|
11
|
altitude units
|
天線海拔高單位,M=meters
|
|
M
|
12
|
undulation
|
大地水準(zhǔn)面與參考橢球面的偏差
|
|
-16.27
|
13
|
undulation units
|
大地水準(zhǔn)面與參考橢球面的偏差單位,M=meters
|
|
M
|
14
|
age
|
差分時(shí)間或齡期,沒有差分?jǐn)?shù)據(jù)時(shí)通常為空
|
|
08
|
15
|
station ID
|
差分基站ID
|
|
AAAA
|
16
|
*xx
|
校驗(yàn)和
|
|
*60
|
17
|
[CR][LF]
|
語句中止符
|
|
[CR][LF]
|
protected function dwgps( string $gps = '' )
{ if ( $gps == '' ) return ['success'=>0,'msg'=>'gps data is empty']; try {
$gps = explode(',',$gps);
$date = isset($gps[0]) ? $gps[0] : 0; $wd = isset($gps[1]) ? $gps[1] : ''; $wd2 = isset($gps[2]) ? $gps[2] : ''; $jd = isset($gps[3]) ? $gps[3] : ''; $jd2 = isset($gps[4]) ? $gps[4] : ''; $state= isset($gps[5]) ? $gps[5] : ''; $count= isset($gps[6]) ? $gps[6] : ''; $hdop = isset($gps[7]) ? $gps[7] : ''; $high = isset($gps[8]) ? $gps[8] : ''; $unit = isset($gps[9]) ? $gps[9] : ''; if ( $wd == '' || $jd == '' ) return ['success'=>0,'msg'=>'data is null'];
$wd = ltrim($wd,'0');
$jd = ltrim($jd,'0');
$wdw = explode('.',$wd);
$wdw1 = $wdw[0];
$wdw2 = $wdw[1];
$wd = intval($wdw1/100) + floatval(($wdw1%100).'.'.$wdw2)/60;
$jdw = explode('.',$jd);
$jdw1 = $jdw[0];
$jdw2 = $jdw[1];
$jd = intval($jdw1/100) + floatval(($jdw1%100).'.'.$jdw2)/60;
$res = ['date'=>$date,'lat'=>(string)$wd,'wd2'=>$wd2,'lng'=>(string)$jd,'jd2'=>$jd2,'state'=>$state,'count'=>$count,'hdop'=>$hdop,'high'=>$high,'unit'=>$unit]; return ['success'=>1,'data'=>$res,'msg'=>''];
} catch ( \Exception $e ) { return ['success'=>0,'msg'=>'解析失敗'];
}
}
public function changepgsv2( array $list = [] )
{
$conf = ['ssl' => ['verify_peer' => false,'verify_peer_name' => false,]];
$max = 20;
$res = [];
$count = count($list);
$psize = ceil($count/$max); for( $i=0;$i<$psize;$i++ ) { $gpsstring = ''; for( $j=($i*$max);$j<($i*$max)+$max;$j++ ) { if ( $j<$count ) { $obj = $list[$j]; $gpsstring .= $obj['lat'].','.$obj['lng'].';'; } } $gpsstring = ($gpsstring,';'); $url = "https://apis.map.qq.com/ws/coord/v1/translate?locations={$gpsstring}&type=1&key=G7GBZ-WL66U-GKCV5-4O5DP-KPGNO-4XFNG"; $vres = file_get_contents($url,false,stream_context_create($conf)); $vres = json_decode($vres,true); if ( $vres['status'] == 0 ) { foreach( $vres['locations'] as $vk=>$vv ) {
$res[] = ['lng'=>(string)$vv['lng'],'lat'=>(string)$vv['lat']];
}
} if ( $psize >1 ) sleep(1);
} return $res;
}
百恒物聯(lián)專業(yè)、專注于
物聯(lián)網(wǎng)應(yīng)用開發(fā)、
物聯(lián)網(wǎng)綜合管控平臺(tái)開發(fā),歡迎廣大用戶來電洽談。
希望本文對(duì)廣大物聯(lián)網(wǎng)技術(shù)研發(fā)人員或從事企業(yè)
物聯(lián)網(wǎng)應(yīng)用開發(fā)公司的團(tuán)隊(duì)有所幫助,如對(duì)此不太理解的,可以與百恒物聯(lián)研發(fā)部聯(lián)系。文章均為百恒物聯(lián)原創(chuàng),轉(zhuǎn)載請(qǐng)注明來自
http://ysmom.cn/index.php/article/417.html