民用導(dǎo)航設(shè)備衛(wèi)星數(shù)據(jù)格式轉(zhuǎn)化為GPS經(jīng)緯度數(shù)據(jù)
1遥皂、民用導(dǎo)航設(shè)備獲取的衛(wèi)星數(shù)據(jù)一般為NMEA協(xié)議源數(shù)據(jù)力喷,它的經(jīng)緯度的數(shù)據(jù)是DDMM.MMMMMM
(度分)格式
2、百度地圖或谷歌地圖的經(jīng)緯度的數(shù)據(jù)格式是DD.DDDDD
3渴肉、將DDMM.MMMMMM
格式轉(zhuǎn)換DD.DDDDD
格式
緯度數(shù)據(jù)轉(zhuǎn)換:
//測試數(shù)據(jù): 廣州一民用導(dǎo)航設(shè)備衛(wèi)星數(shù)據(jù)(遵循NMEA-0183協(xié)議的民用設(shè)備導(dǎo)航衛(wèi)星數(shù)據(jù))@{@"lat":@"2322.0897",@"lon":@"11315.3628",}
/**
民用導(dǎo)航設(shè)備衛(wèi)星數(shù)據(jù)格式轉(zhuǎn)化為GPS緯度數(shù)據(jù)
@param lon 衛(wèi)星數(shù)據(jù)
@return GPS緯度數(shù)據(jù)
*/
- (double)latitudeFromSatelliteDataFormat:(NSString *)lat {
if (lat.length <= 0) {// 若無數(shù)據(jù)返回天安門GPS緯度數(shù)據(jù)
return 39.915119;
}
double lat_temp = 0;
int lat_loc = 0;
int dd_int = 0;
long mm_int = 0;
double lat_loc_double = 0;
char *lat_str = (char *)[lat UTF8String]; //OC字符串轉(zhuǎn)化為C字符串
lat_temp = atof(lat_str);
lat_loc =lat_temp*100000; //轉(zhuǎn)換為整數(shù)
dd_int = lat_loc/10000000; //取出dd
mm_int = lat_loc%10000000; //取出MM部分
lat_loc_double = dd_int + (double)mm_int/60/100000;//換算為Onenet格式
return lat_loc_double;
}
經(jīng)度數(shù)據(jù)轉(zhuǎn)換:
/**
民用導(dǎo)航設(shè)備衛(wèi)星數(shù)據(jù)格式轉(zhuǎn)化為GPS經(jīng)度數(shù)據(jù)
@param lon 衛(wèi)星數(shù)據(jù)
@return GPS經(jīng)度數(shù)據(jù)
*/
- (double)longitudeFromSatelliteDataFormat:(NSString *)lon {
if (lon.length <= 0) {// 若無數(shù)據(jù)返回天安門GPS經(jīng)度數(shù)據(jù)
return 116.403963;
}
double lon_temp = 0;
int lon_loc = 0;
int dd_int = 0;
long mm_int = 0;
double lon_loc_double = 0;
char *lon_str = (char *)[lon UTF8String]; //OC字符串轉(zhuǎn)化為C字符串
lon_temp = atof(lon_str);
lon_loc =lon_temp*100000; //轉(zhuǎn)換為整數(shù)
dd_int = lon_loc/10000000; //取出dd
mm_int = lon_loc%10000000; //取出MM部分
lon_loc_double = dd_int + (double)mm_int/60/100000;//換算為Onenet格式
return lon_loc_double;
}