修改全服
This commit is contained in:
parent
0a4425d705
commit
4a7423a5b9
@ -2,10 +2,10 @@ package com.yunbao.common.utils;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.tencent.map.geolocation.TencentLocation;
|
//import com.tencent.map.geolocation.TencentLocation;
|
||||||
import com.tencent.map.geolocation.TencentLocationListener;
|
//import com.tencent.map.geolocation.TencentLocationListener;
|
||||||
import com.tencent.map.geolocation.TencentLocationManager;
|
//import com.tencent.map.geolocation.TencentLocationManager;
|
||||||
import com.tencent.map.geolocation.TencentLocationRequest;
|
//import com.tencent.map.geolocation.TencentLocationRequest;
|
||||||
import com.yunbao.common.CommonAppConfig;
|
import com.yunbao.common.CommonAppConfig;
|
||||||
import com.yunbao.common.CommonAppContext;
|
import com.yunbao.common.CommonAppContext;
|
||||||
import com.yunbao.common.bean.TxLocationBean;
|
import com.yunbao.common.bean.TxLocationBean;
|
||||||
@ -23,12 +23,12 @@ import java.util.List;
|
|||||||
public class LocationUtil {
|
public class LocationUtil {
|
||||||
private static final String TAG = "定位";
|
private static final String TAG = "定位";
|
||||||
private static LocationUtil sInstance;
|
private static LocationUtil sInstance;
|
||||||
private TencentLocationManager mLocationManager;
|
// private TencentLocationManager mLocationManager;
|
||||||
private boolean mLocationStarted;
|
private boolean mLocationStarted;
|
||||||
private boolean mNeedPostLocationEvent;//是否需要发送定位成功事件
|
private boolean mNeedPostLocationEvent;//是否需要发送定位成功事件
|
||||||
|
|
||||||
private LocationUtil() {
|
private LocationUtil() {
|
||||||
mLocationManager = TencentLocationManager.getInstance(CommonAppContext.sInstance);
|
// mLocationManager = TencentLocationManager.getInstance(CommonAppContext.sInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocationUtil getInstance() {
|
public static LocationUtil getInstance() {
|
||||||
@ -42,26 +42,26 @@ public class LocationUtil {
|
|||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
private TencentLocationListener mLocationListener = new TencentLocationListener() {
|
// private TencentLocationListener mLocationListener = new TencentLocationListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void onLocationChanged(TencentLocation location, int code, String reason) {
|
// public void onLocationChanged(TencentLocation location, int code, String reason) {
|
||||||
if (code == TencentLocation.ERROR_OK) {
|
// if (code == TencentLocation.ERROR_OK) {
|
||||||
double lng = location.getLongitude();//经度
|
// double lng = location.getLongitude();//经度
|
||||||
double lat = location.getLatitude();//纬度
|
// double lat = location.getLatitude();//纬度
|
||||||
L.e(TAG, "获取经纬度成功------>经度:" + lng + ",纬度:" + lat);
|
// L.e(TAG, "获取经纬度成功------>经度:" + lng + ",纬度:" + lat);
|
||||||
CommonHttpUtil.getAddressInfoByTxLocaitonSdk(lng, lat, 0, 1, CommonHttpConsts.GET_LOCAITON, mCallback);
|
// CommonHttpUtil.getAddressInfoByTxLocaitonSdk(lng, lat, 0, 1, CommonHttpConsts.GET_LOCAITON, mCallback);
|
||||||
if (mNeedPostLocationEvent) {
|
// if (mNeedPostLocationEvent) {
|
||||||
EventBus.getDefault().post(new LocationEvent(lng, lat));
|
// EventBus.getDefault().post(new LocationEvent(lng, lat));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onStatusUpdate(String s, int i, String s1) {
|
// public void onStatusUpdate(String s, int i, String s1) {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
private HttpCallback mCallback = new HttpCallback() {
|
private HttpCallback mCallback = new HttpCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -86,29 +86,29 @@ public class LocationUtil {
|
|||||||
|
|
||||||
//启动定位
|
//启动定位
|
||||||
public void startLocation() {
|
public void startLocation() {
|
||||||
if (!mLocationStarted && mLocationManager != null) {
|
// if (!mLocationStarted && mLocationManager != null) {
|
||||||
mLocationStarted = true;
|
// mLocationStarted = true;
|
||||||
L.e(TAG, "开启定位");
|
// L.e(TAG, "开启定位");
|
||||||
TencentLocationRequest request = TencentLocationRequest
|
// TencentLocationRequest request = TencentLocationRequest
|
||||||
.create()
|
// .create()
|
||||||
.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_GEO)
|
// .setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_GEO)
|
||||||
.setInterval(60 * 60 * 1000);//1小时定一次位
|
// .setInterval(60 * 60 * 1000);//1小时定一次位
|
||||||
|
//
|
||||||
//当定位周期大于0时, 不论是否有得到新的定位结果, 位置监听器都会按定位周期定时被回调;
|
// //当定位周期大于0时, 不论是否有得到新的定位结果, 位置监听器都会按定位周期定时被回调;
|
||||||
// 当定位周期等于0时, 仅当有新的定位结果时, 位置监听器才会被回调(即, 回调时机存在不确定性).
|
// // 当定位周期等于0时, 仅当有新的定位结果时, 位置监听器才会被回调(即, 回调时机存在不确定性).
|
||||||
// 如果需要周期性回调, 建议将 定位周期 设置为 5000-10000ms
|
// // 如果需要周期性回调, 建议将 定位周期 设置为 5000-10000ms
|
||||||
mLocationManager.requestLocationUpdates(request, mLocationListener);
|
// mLocationManager.requestLocationUpdates(request, mLocationListener);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//停止定位
|
//停止定位
|
||||||
public void stopLocation() {
|
public void stopLocation() {
|
||||||
CommonHttpUtil.cancel(CommonHttpConsts.GET_LOCAITON);
|
// CommonHttpUtil.cancel(CommonHttpConsts.GET_LOCAITON);
|
||||||
if (mLocationStarted && mLocationManager != null) {
|
// if (mLocationStarted && mLocationManager != null) {
|
||||||
L.e(TAG, "关闭定位");
|
// L.e(TAG, "关闭定位");
|
||||||
mLocationManager.removeUpdates(mLocationListener);
|
// mLocationManager.removeUpdates(mLocationListener);
|
||||||
mLocationStarted = false;
|
// mLocationStarted = false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNeedPostLocationEvent(boolean needPostLocationEvent) {
|
public void setNeedPostLocationEvent(boolean needPostLocationEvent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user