if (mCallback != null)
mCallback.on_locating_changed(get_gps_status());
}
- if (nmeastr.startsWith("$GPGLL,") || nmeastr.startsWith("$GNGLL,")) {
+ if (nmeastr.startsWith("$GPGLL,") || nmeastr.startsWith("$GNGLL,") || nmeastr.startsWith("$BDGLL,")) {
String tmplist[] = nmeastr.split(",");
// GPGLL编辑
//(地理定位信息)
//字段5:UTC时间,hhmmss.sss格式
//字段6:状态,A=定位,V=未定位
//字段7:校验值($与*之间的数异或后的值)
- String Lat = tmplist[1];
- String lon = tmplist[3];
- String fixed = tmplist[6];
+ if (tmplist.length > 6) {
+ String Lat = tmplist[1];
+ String lon = tmplist[3];
+ String fixed = tmplist[6];
// ICLogger.i("GPGLL Lat="+Lat+",Lon="+lon+",fixed="+fixed);
-
- } else if (nmeastr.startsWith("$GPRMC,") || nmeastr.startsWith("$GNRMC,")) {
+ }
+ } else if (nmeastr.startsWith("$GPRMC,") || nmeastr.startsWith("$GNRMC,") || nmeastr.startsWith("$BDRMC,")) {
// GPRMC编辑
//(推荐定位信息数据格式)
//例:$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50
//字段12:模式,A=自动,D=差分,E=估测,N=数据无效(3.0协议内容)
//字段13:校验值($与*之间的数异或后的值)
String tmplist[] = nmeastr.split(",");
- String utctime = tmplist[1];
- String Lat = tmplist[3];
- String lon = tmplist[5];
- String fixed = tmplist[2];
- String speed = tmplist[7];
+ if (tmplist.length > 7) {
+ String utctime = tmplist[1];
+ String Lat = tmplist[3];
+ String lon = tmplist[5];
+ String fixed = tmplist[2];
+ String speed = tmplist[7];
// ICLogger.i("GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
// if (Config.LOG_TOFILE)
// FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "GPS", "GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
- if (fixed.trim().equals("A")) {
- if (speed.trim().isEmpty()) speed = "0.0";
- runtime.getLocationInstance().setSpeed(Float.valueOf(speed));
- }
+ if (fixed.trim().equals("A")) {
+ if (speed.trim().isEmpty()) speed = "0.0";
+ runtime.getLocationInstance().setSpeed(Float.valueOf(speed));
+ }
+ }
} else if (nmeastr.startsWith("$GPGSV,") || nmeastr.startsWith("$GLGSV,") || nmeastr.startsWith("$GAGSV,") || nmeastr.startsWith("$GBGSV,") || nmeastr.startsWith("$BDGSV,")) {
// 字段16:校验值($与*之间的数异或后的值)
String tmplist[] = nmeastr.split(",");
- int maxPageCount = 0;
- int currentPage = 0;
- int SatlitesCount = 0;
+ if (tmplist.length > 3) {
+ int maxPageCount = 0;
+ int currentPage = 0;
+ int SatlitesCount = 0;
- try {
- maxPageCount = Integer.valueOf(tmplist[1]);
- } catch (Exception e) {
- }
- try {
- currentPage = Integer.valueOf(tmplist[2]);
- } catch (Exception e) {
- }
- try {
- SatlitesCount = Integer.valueOf(tmplist[3]);
- } catch (Exception e) {
- }
- if (maxPageCount > 0 && currentPage == 1) {
- //第一页把数组初始化一遍。
- satindex = 0;
- gps_status.satlite_numbss = SatlitesCount;
- }
- int satcount = (tmplist.length - 4) / 4;
-// ICLogger.i("Nmea :"+nmeastr+" "+satcount);
- runtime.getLocationInstance().set_adding_satlite_flag(true);
- for (int i = 0; i < satcount; i++) {
- satindex++;
- String prn = tmplist[i * 4 + 4];
- String snr = tmplist[i * 4 + 4 + 3];
- if (snr.contains("*")) {
- snr = snr.substring(0, snr.indexOf("*"));
- }
- if (snr.trim().isEmpty()) {
- snr = "0";
+ try {
+ maxPageCount = Integer.valueOf(tmplist[1]);
+ } catch (Exception e) {
}
-// ICLogger.i("Sat=" + satindex + ",prn=" + prn + ",snr=" + snr);
-
- int intprn = 0;
try {
- intprn = Integer.valueOf(prn);
+ currentPage = Integer.valueOf(tmplist[2]);
} catch (Exception e) {
}
- float floatsnr = 0;
try {
- floatsnr = Float.valueOf(snr);
+ SatlitesCount = Integer.valueOf(tmplist[3]);
} catch (Exception e) {
}
- if (floatsnr > 0) {
- //排序取得最大3个SNR
- get3MaxSnrSatellite(new ICLocation.GpsSatellitePriv(intprn, floatsnr));
- runtime.getLocationInstance().numSatelliteList.add(new ICLocation.GpsSatellitePriv(intprn, floatsnr));
- gps_status.numSatelliteList.add(new ICLocation.GpsSatellitePriv(intprn, floatsnr));
+ if (maxPageCount > 0 && currentPage == 1) {
+ //第一页把数组初始化一遍。
+ satindex = 0;
+ gps_status.satlite_numbss = SatlitesCount;
+ }
+ int satcount = (tmplist.length - 4) / 4;
+// ICLogger.i("Nmea :"+nmeastr+" "+satcount);
+ runtime.getLocationInstance().set_adding_satlite_flag(true);
+ for (int i = 0; i < satcount; i++) {
+ satindex++;
+ String prn = tmplist[i * 4 + 4];
+ String snr = tmplist[i * 4 + 4 + 3];
+ if (snr.contains("*")) {
+ snr = snr.substring(0, snr.indexOf("*"));
+ }
+ if (snr.trim().isEmpty()) {
+ snr = "0";
+ }
+// ICLogger.i("Sat=" + satindex + ",prn=" + prn + ",snr=" + snr);
+
+ int intprn = 0;
+ try {
+ intprn = Integer.valueOf(prn);
+ } catch (Exception e) {
+ }
+ float floatsnr = 0;
+ try {
+ floatsnr = Float.valueOf(snr);
+ } catch (Exception e) {
+ }
+ if (floatsnr > 0) {
+ //排序取得最大3个SNR
+ get3MaxSnrSatellite(new ICLocation.GpsSatellitePriv(intprn, floatsnr));
+ runtime.getLocationInstance().numSatelliteList.add(new ICLocation.GpsSatellitePriv(intprn, floatsnr));
+ gps_status.numSatelliteList.add(new ICLocation.GpsSatellitePriv(intprn, floatsnr));
+ }
}
}
runtime.getLocationInstance().set_adding_satlite_flag(false);
- } else if (nmeastr.startsWith("$GPGGA,") || nmeastr.startsWith("$GNGGA,")) {
+ } else if (nmeastr.startsWith("$GPGGA,") || nmeastr.startsWith("$GNGGA,") || nmeastr.startsWith("$BDGGA,")) {
// GPGGA编辑
//(定位信息)
// 字段15:校验值($与*之间的数异或后的值)
String tmplist[] = nmeastr.split(",");
- String utctime = tmplist[1];
- String Lat = tmplist[2];
- String lon = tmplist[4];
- String latname = tmplist[3];
- String lonname = tmplist[5];
- String fixed = tmplist[6];
- String usedStarts = tmplist[7];
- String hdop = tmplist[8];
- String altitude = tmplist[9];
- ICLogger.d("altitude ==> " + altitude);
-
- if ((fixed.trim().equals("1")) || (fixed.trim().equals("2")) || (fixed.trim().equals("6"))) {
- // 转换GPS坐标为度,以便在各种应用中可以方便查找。
- try {
- latitude = Double.valueOf(Lat);
- longitude = Double.valueOf(lon);
- } catch (Exception e) {
- }
- // 转换单位,从分转换到度
- double intdu = (int) (longitude / 100f); //小数转换到分为单位
- double du = (longitude - intdu * 100) / 60f;
- double last = intdu + du;
- longitude = last;
- intdu = (int) (latitude / 100f); //小数转换到分为单位
- du = (latitude - intdu * 100) / 60f;
- last = intdu + du;
- latitude = last;
-
- // 经纬度 保留4位小数点
- DecimalFormat df = new DecimalFormat("#.0000000");
- strLatitude = df.format(latitude);
- strLongitude = df.format(longitude);
-
- //定位
- StringBuilder sb = new StringBuilder();
- sb.append("GPGGA, location time= " + TimeUtil.getLocalTime() +
- ", FixedCount=" + locationFixedCount + ", " +
- "GPSTime=" + utctime + ", Lat(" + latname + ")=" + Lat +
- " (" + strLatitude + "), Lon(" + lonname + ")=" +
- lon + " (" + strLongitude + "), fixed=" + fixed +
- ", hdop=" + hdop + ", usedStarts=" + usedStarts);
- ICLogger.i(sb.toString());
- if (Config.LOG_TOFILE)
- ICLogger.logToFile("GPS", sb.toString());
- //定位了,
- if (hdop != null && hdop.trim().length() > 0 && Float.valueOf(hdop) < ICLocation.MAX_HDOP) {
- locationFixedCount++;
- } else {
- ICLogger.i("HDOP is larger than " + ICLocation.MAX_HDOP + " , skip this location!");
- if (Config.LOG_TOFILE) {
- ICLogger.logToFile("GPS", "HDOP is larger than " + ICLocation.MAX_HDOP + " , skip this location!");
+ if (tmplist.length > 8) {
+ String utctime = tmplist[1];
+ String Lat = tmplist[2];
+ String lon = tmplist[4];
+ String latname = tmplist[3];
+ String lonname = tmplist[5];
+ String fixed = tmplist[6];
+ String usedStarts = tmplist[7];
+ String hdop = tmplist[8];
+ String altitude = tmplist[9];
+ ICLogger.d("altitude ==> " + altitude);
+
+ if ((fixed.trim().equals("1")) || (fixed.trim().equals("2")) || (fixed.trim().equals("6"))) {
+ // 转换GPS坐标为度,以便在各种应用中可以方便查找。
+ try {
+ latitude = Double.valueOf(Lat);
+ longitude = Double.valueOf(lon);
+ } catch (Exception e) {
}
- }
- if (locationFixedCount > MaxFixedTimes) {
+ // 转换单位,从分转换到度
+ double intdu = (int) (longitude / 100f); //小数转换到分为单位
+ double du = (longitude - intdu * 100) / 60f;
+ double last = intdu + du;
+ longitude = last;
+ intdu = (int) (latitude / 100f); //小数转换到分为单位
+ du = (latitude - intdu * 100) / 60f;
+ last = intdu + du;
+ latitude = last;
+
+ // 经纬度 保留4位小数点
+ DecimalFormat df = new DecimalFormat("#.0000000");
+ strLatitude = df.format(latitude);
+ strLongitude = df.format(longitude);
+
+ //定位
+ StringBuilder sb = new StringBuilder();
+ sb.append("GPGGA, location time= " + TimeUtil.getLocalTime() +
+ ", FixedCount=" + locationFixedCount + ", " +
+ "GPSTime=" + utctime + ", Lat(" + latname + ")=" + Lat +
+ " (" + strLatitude + "), Lon(" + lonname + ")=" +
+ lon + " (" + strLongitude + "), fixed=" + fixed +
+ ", hdop=" + hdop + ", usedStarts=" + usedStarts);
+ ICLogger.i(sb.toString());
+ if (Config.LOG_TOFILE)
+ ICLogger.logToFile("GPS", sb.toString());
+ //定位了,
+ if (hdop != null && hdop.trim().length() > 0 && Float.valueOf(hdop) < ICLocation.MAX_HDOP) {
+ locationFixedCount++;
+ } else {
+ ICLogger.i("HDOP is larger than " + ICLocation.MAX_HDOP + " , skip this location!");
+ if (Config.LOG_TOFILE) {
+ ICLogger.logToFile("GPS", "HDOP is larger than " + ICLocation.MAX_HDOP + " , skip this location!");
+ }
+ }
+ if (locationFixedCount > MaxFixedTimes) {
/*
只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。
延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。
*/
- runtime.getLocationInstance().setLocation(Lat, lon);
- runtime.getLocationInstance().setLocationGPS(strLatitude, strLongitude);
- runtime.getLocationInstance().setLocationlatlonName(latname, lonname);
- runtime.getLocationInstance().setUsedStarts(Integer.valueOf(usedStarts.trim()));
- runtime.getLocationInstance().setHod(Float.valueOf(hdop.trim()));
- runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED);
- ICLogger.i("定位" + locationFixedCount + "次 > " + MaxFixedTimes + ", set LOCATION_FIXED ");
- if (Config.LOG_TOFILE)
- ICLogger.logToFile("GPS", "定位" + locationFixedCount + "次 > " + MaxFixedTimes + ", set LOCATION_FIXED ");
- if (!noStop) {
- stopListen();
+ runtime.getLocationInstance().setLocation(Lat, lon);
+ runtime.getLocationInstance().setLocationGPS(strLatitude, strLongitude);
+ runtime.getLocationInstance().setLocationlatlonName(latname, lonname);
+ runtime.getLocationInstance().setUsedStarts(Integer.valueOf(usedStarts.trim()));
+ runtime.getLocationInstance().setHod(Float.valueOf(hdop.trim()));
+ runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED);
+ ICLogger.i("定位" + locationFixedCount + "次 > " + MaxFixedTimes + ", set LOCATION_FIXED ");
+ if (Config.LOG_TOFILE)
+ ICLogger.logToFile("GPS", "定位" + locationFixedCount + "次 > " + MaxFixedTimes + ", set LOCATION_FIXED ");
+ if (!noStop) {
+ stopListen();
+ }
}
+ gps_status.locating_status = 1; //fixed
+ } else {
+ gps_status.locating_status = 0; //notfixed
+ }
+ try {
+ gps_status.hdop = Float.valueOf(hdop.trim());
+ gps_status.used_gps_numbs = Integer.valueOf(usedStarts.trim());
+ } catch (Exception e) {
}
- gps_status.locating_status = 1; //fixed
- } else {
- gps_status.locating_status = 0; //notfixed
- }
- try {
- gps_status.hdop = Float.valueOf(hdop.trim());
- gps_status.used_gps_numbs = Integer.valueOf(usedStarts.trim());
- } catch (Exception e) {
- }
- } else if (nmeastr.startsWith("$GPGSA,") || nmeastr.startsWith("$GNGSA,")) {
+ }
+ }else if (nmeastr.startsWith("$GPGSA,") || nmeastr.startsWith("$GNGSA,") || nmeastr.startsWith("$BDGSA,")) {
// GPGSA编辑
//( 当前卫星信息)
//做个热启动
return true;//gpsHotStart();
- } else {
+ }else {
ICLogger.i(" location listening, skip !");
runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_SEARCHING);