@@ -33,6 +33,7 @@ import com.android.views.indicators.SpringBar; |
||
| 33 | 33 |
|
| 34 | 34 |
import java.io.File; |
| 35 | 35 |
|
| 36 |
+import ai.pai.client.BuildConfig; |
|
| 36 | 37 |
import ai.pai.client.R; |
| 37 | 38 |
import ai.pai.client.beans.GroupInfo; |
| 38 | 39 |
import ai.pai.client.db.DBService; |
@@ -99,7 +100,7 @@ public class MainActivity extends AppCompatActivity |
||
| 99 | 100 |
protected void onResume() {
|
| 100 | 101 |
super.onResume(); |
| 101 | 102 |
callGuideBtn.setVisibility(TextUtils.isEmpty(Preferences.getInstance(this).getTourGuidePhone()) ? View.INVISIBLE : View.VISIBLE); |
| 102 |
- if(Preferences.getInstance(this).isTourMode()){
|
|
| 103 |
+ if(Preferences.getInstance(this).isTourMode()|| BuildConfig.DEBUG){
|
|
| 103 | 104 |
Intent intent = new Intent(this, MyLocationService.class); |
| 104 | 105 |
intent.putExtra("command",MyLocationService.COMMAND_START_LOCATION);
|
| 105 | 106 |
startService(intent); |
@@ -9,8 +9,16 @@ import com.amap.api.location.AMapLocation; |
||
| 9 | 9 |
import com.amap.api.location.AMapLocationClient; |
| 10 | 10 |
import com.amap.api.location.AMapLocationClientOption; |
| 11 | 11 |
import com.amap.api.location.AMapLocationListener; |
| 12 |
+import com.android.common.executors.ThreadExecutor; |
|
| 12 | 13 |
import com.android.common.utils.LogHelper; |
| 13 | 14 |
|
| 15 |
+import java.util.HashMap; |
|
| 16 |
+ |
|
| 17 |
+import ai.pai.client.BuildConfig; |
|
| 18 |
+import ai.pai.client.db.Preferences; |
|
| 19 |
+import ai.pai.client.utils.HttpPostTask; |
|
| 20 |
+import ai.pai.client.utils.UrlContainer; |
|
| 21 |
+ |
|
| 14 | 22 |
|
| 15 | 23 |
public class MyLocationService extends Service {
|
| 16 | 24 |
|
@@ -21,6 +29,10 @@ public class MyLocationService extends Service {
|
||
| 21 | 29 |
public static final int COMMAND_STOP_LOCATION = 9802; |
| 22 | 30 |
public static final int COMMAND_DESTROY_LOCATION = 9803; |
| 23 | 31 |
|
| 32 |
+ private double lastLat; |
|
| 33 |
+ private double lastLon; |
|
| 34 |
+ private double repeatTime; |
|
| 35 |
+ |
|
| 24 | 36 |
private int status = 0; // 0:未开始 1:已开始 2:已暂停 |
| 25 | 37 |
|
| 26 | 38 |
@Override |
@@ -90,7 +102,7 @@ public class MyLocationService extends Service {
|
||
| 90 | 102 |
mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式 |
| 91 | 103 |
mOption.setGpsFirst(false);//可选,设置是否gps优先,只在高精度模式下有效。默认关闭 |
| 92 | 104 |
mOption.setHttpTimeOut(30000);//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效 |
| 93 |
- mOption.setInterval(600*1000);//可选,设置定位间隔。默认为600秒 |
|
| 105 |
+ mOption.setInterval(30*1000);//可选,设置定位间隔。默认为600秒 |
|
| 94 | 106 |
mOption.setNeedAddress(true);//可选,设置是否返回逆地理地址信息。默认是true |
| 95 | 107 |
mOption.setOnceLocation(false);//可选,设置是否单次定位。默认是false |
| 96 | 108 |
mOption.setOnceLocationLatest(false);//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用 |
@@ -109,6 +121,7 @@ public class MyLocationService extends Service {
|
||
| 109 | 121 |
double lat = loc.getLatitude(); |
| 110 | 122 |
double lon = loc.getLongitude(); |
| 111 | 123 |
LogHelper.d("czy","lat = "+lat+"lon="+lon+"adr="+loc.getAddress());
|
| 124 |
+ reportLocationWhenTourMode(lat,lon); |
|
| 112 | 125 |
} |
| 113 | 126 |
}; |
| 114 | 127 |
|
@@ -164,4 +177,25 @@ public class MyLocationService extends Service {
|
||
| 164 | 177 |
} |
| 165 | 178 |
} |
| 166 | 179 |
|
| 180 |
+private void reportLocationWhenTourMode(double lat, double lon){
|
|
| 181 |
+ if(lat == lastLat && lon ==lastLon && repeatTime<5){
|
|
| 182 |
+ repeatTime++; |
|
| 183 |
+ return; |
|
| 184 |
+ } |
|
| 185 |
+ repeatTime = 0; |
|
| 186 |
+ lastLat = lat; |
|
| 187 |
+ lastLon = lon; |
|
| 188 |
+ if(Preferences.getInstance(this).isTourMode()|| BuildConfig.DEBUG){
|
|
| 189 |
+ HashMap<String,String> params = new HashMap<String,String>(); |
|
| 190 |
+ String userId = Preferences.getInstance(this).getUserId(); |
|
| 191 |
+ if(userId.length()==0){
|
|
| 192 |
+ return; |
|
| 193 |
+ } |
|
| 194 |
+ params.put("user_id",userId);
|
|
| 195 |
+ params.put("lon",String.valueOf(lon));
|
|
| 196 |
+ params.put("lat",String.valueOf(lat));
|
|
| 197 |
+ new HttpPostTask(this,params).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.GEO_LOCATION_URL); |
|
| 198 |
+ } |
|
| 199 |
+} |
|
| 200 |
+ |
|
| 167 | 201 |
} |