Skip to content

Commit f8b7486

Browse files
author
wenlong
committed
修改定位为GPS
1 parent 66bac36 commit f8b7486

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<string name="app_name">SimpleExample</string>
55
<string name="menu_settings">Settings</string>
66
<string name="hello_world">Hello world!</string>
7-
<string name="stop">{"MAF":"0\r\n","AVGSPD":"029","STARTS":"068","MILE-T":"0003.6","MAXRPM":"11642","POWER":"0","RACLS":"000","FUELS":"0037.241","FUEL-T":"000.605","MAXACL":"008","TIMES":"0007.7","MAXSPD":"030","BRAKES":"000","MINRPM":"00000","MILES":"005558.7"}</string>
8-
<string name="pid">{"MPH":"018.943\r\n","MILE-T":"0001.0","VBAT":"11.7","ECT":"065","TIMES":"00127","SPD":"030","RPM":"11630","LOD":"000.0"}</string>
7+
<string name="stop">{"MAF":"0","AVGSPD":"000","STARTS":"006","MILE-T":"0000.3","MAXRPM":"13663","POWER":"0","RACLS":"000","FUELS":"0000.679","FUEL-T":"000.424","MAXACL":"002","TIMES":"0000.0","MAXSPD":"009","BRAKES":"000","MINRPM":"00000","MILES":"000000.5"}</string>
8+
<string name="pid">{"MPH":"118.844L\/hKM","MILE-T":"0000.1","VBAT":"12.2","ECT":"087","TIMES":"00077","SPD":"009","RPM":"13631","LOD":"093.7"}</string>
99
</resources>

src/com/obd/service/DataSyncService.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
public class DataSyncService extends Service{
4444
public final static int RefreshTime = 30*1000;
45-
45+
public static final boolean USE_GPS_LOCATION = true;
4646
private static String TAG = "DataSyncService";
4747
private GetLoaction mGetLoaction = new GetLoaction();
4848
NetWork mNetWork = new NetWork();
@@ -73,8 +73,6 @@ private void initSingle(){
7373
MyPhoneStateListener MyListener = new MyPhoneStateListener();
7474
TelephonyManager tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
7575
tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
76-
77-
mGetLoaction.uploadBattery(0);
7876
}
7977

8078
@Override
@@ -108,7 +106,13 @@ private void locationInit(){
108106
mLocClient.registerLocationListener(myListener);
109107
LocationClientOption option = new LocationClientOption();
110108
option.setLocationMode(LocationMode.Hight_Accuracy);//设置定位模式//option.setOpenGps(true);// 打开gps
111-
option.setCoorType("bd09ll"); // 设置坐标类型
109+
110+
option.setLocationMode(LocationMode.Hight_Accuracy);
111+
if(USE_GPS_LOCATION)
112+
option.setCoorType("gcj02"); // 设置坐标类型
113+
else
114+
option.setCoorType("bd09ll"); // 设置坐标类型
115+
112116
option.setScanSpan(RefreshTime);
113117
mLocClient.setLocOption(option);
114118

@@ -212,13 +216,11 @@ public String getIMEI(){
212216
String imei = QuickShPref.getString(QuickShPref.IEMI);
213217
if(imei == null || imei.length() == 0){
214218
imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getDeviceId();
215-
if(imei == null)
216-
imei = "";
217-
Log.d("ieme", imei);
219+
Log.d("imei=", imei);
218220
QuickShPref.putValueObject(QuickShPref.IEMI, imei);
219-
mGetLoaction.mIMEI = imei;
220-
StatusInface.getInstance().mIEMI = imei;
221221
}
222+
mGetLoaction.mIMEI = imei;
223+
StatusInface.getInstance().mIEMI = imei;
222224
return imei;
223225
}
224226

@@ -279,7 +281,7 @@ private BDLocation getBDLocation(BDLocation loc){
279281
if(lastLocTime!=null)
280282
MyLog.D("compareTo="+time.compareTo(lastLocTime));
281283
time = mGetLoaction.formatTime(time);
282-
if(lastLocTime==null || (time!=null&&time.compareTo(lastLocTime)>0)){
284+
if(lastLocTime==null || (time!=null && time.compareTo(lastLocTime)>0)){
283285
loc.setTime(time);
284286
saveLastPos(loc);
285287
}

src/com/obd/simpleexample/StatusInface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String getTime(){
8181
if(date.getYear()<113){
8282
String time = QuickShPref.getString(QuickShPref.Time);
8383
if(time == null)
84-
time = "20150330101010";
84+
time = null;
8585
return time;
8686
}
8787
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");

src/com/obd/widget/GetLoaction.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.util.Log;
1111
import com.baidu.location.BDLocation;
1212
import com.obd.app.bean.DROInfo;
13+
import com.obd.service.DataSyncService;
1314
import com.obd.simpleexample.StatusInface;
1415
import com.obd.utils.DBmanager;
1516
import com.obd.utils.MyLog;
@@ -37,6 +38,10 @@ public String uploadPos(BDLocation location) {
3738
MyLog.E("定位数据为空,不上报");
3839
return null;
3940
}
41+
Date temDate = new Date();
42+
if(temDate == null || temDate.getYear() < 113){
43+
MyLog.E("当前系统时间无效,不上报");
44+
}
4045

4146
String time = location.getTime();
4247

@@ -74,7 +79,13 @@ public String uploadPos(BDLocation location) {
7479
f = 0x0F; // 基站 15
7580
}
7681

77-
82+
if(DataSyncService.USE_GPS_LOCATION){
83+
Gps gps84 = PositionUtil.gcj_To_Gps84(lat, lon);
84+
lat = gps84.mLat;
85+
lon = gps84.mLon;
86+
}else{
87+
f = 0x6f;
88+
}
7889

7990

8091
int lonDu = (int) lon;
@@ -111,7 +122,7 @@ public String uploadPos(BDLocation location) {
111122
buffer.append(time.subSequence(17, 19));
112123
buffer.append(latString);
113124
buffer.append(lonString);
114-
buffer.append((char) 0x6f);
125+
buffer.append((char)f);
115126
buffer.append(speed);
116127
buffer.append(direction);
117128
buffer.append(time.subSequence(8, 10));

src/com/obd/widget/NetWork.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void sleep(int dur){
133133
Thread.sleep(dur);
134134
} catch (InterruptedException e) {
135135
// TODO Auto-generated catch block
136-
e.printStackTrace();
136+
//e.printStackTrace();
137137
}
138138

139139
}

0 commit comments

Comments
 (0)