[dev_arch_opt_3.0]
[Change] [ 1、解除数据中心对高德地图的依赖 ] Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -55,7 +55,6 @@ dependencies {
|
|||||||
implementation rootProject.ext.dependencies.androidxroomktx
|
implementation rootProject.ext.dependencies.androidxroomktx
|
||||||
|
|
||||||
implementation rootProject.ext.dependencies.mogoaicloudtelematic
|
implementation rootProject.ext.dependencies.mogoaicloudtelematic
|
||||||
implementation rootProject.ext.dependencies.amapnavi3dmap
|
|
||||||
implementation project(':libraries:mogo-obu')
|
implementation project(':libraries:mogo-obu')
|
||||||
implementation project(':libraries:mogo-adas')
|
implementation project(':libraries:mogo-adas')
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,21 @@
|
|||||||
package com.mogo.eagle.core.function.datacenter.location
|
package com.mogo.eagle.core.function.datacenter.location
|
||||||
|
|
||||||
import com.amap.api.location.AMapLocation
|
|
||||||
import com.amap.api.location.AMapLocationClient
|
|
||||||
import com.amap.api.location.AMapLocationClientOption
|
|
||||||
import com.amap.api.location.AMapLocationListener
|
|
||||||
import com.mogo.commons.AbsMogoApplication
|
import com.mogo.commons.AbsMogoApplication
|
||||||
import com.mogo.commons.constants.SharedPrefsConstants
|
import com.mogo.commons.constants.SharedPrefsConstants
|
||||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||||
import com.mogo.eagle.core.data.enums.DataSourceType
|
import com.mogo.eagle.core.data.enums.DataSourceType
|
||||||
import com.mogo.eagle.core.data.map.MogoLocation
|
import com.mogo.eagle.core.data.map.MogoLocation
|
||||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisGnssListener
|
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisGnssListener
|
||||||
|
import com.mogo.eagle.core.function.api.map.listener.IGaoDeMapLocationListener
|
||||||
import com.mogo.eagle.core.function.api.obu.IMoGoObuLocationWGS84Listener
|
import com.mogo.eagle.core.function.api.obu.IMoGoObuLocationWGS84Listener
|
||||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisGnssListenerManager
|
import com.mogo.eagle.core.function.call.autopilot.CallerChassisGnssListenerManager
|
||||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
|
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
|
||||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
|
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
|
||||||
|
import com.mogo.eagle.core.function.call.map.CallerGaoDeMapLocationListenerManager
|
||||||
import com.mogo.eagle.core.function.call.obu.CallerObuLocationWGS84ListenerManager
|
import com.mogo.eagle.core.function.call.obu.CallerObuLocationWGS84ListenerManager
|
||||||
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
|
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
|
||||||
import com.mogo.eagle.core.utilcode.util.CoordinateTransform
|
|
||||||
import com.mogo.eagle.core.utilcode.util.MultiDisplayUtils
|
import com.mogo.eagle.core.utilcode.util.MultiDisplayUtils
|
||||||
import com.mogo.eagle.core.utilcode.util.TimeUtils
|
import com.mogo.eagle.core.utilcode.util.TimeUtils
|
||||||
import com.mogo.eagle.core.utilcode.util.Utils
|
|
||||||
import com.mogo.support.obu.model.MogoObuHvBasicsData
|
|
||||||
import mogo.telematics.pad.MessagePad
|
import mogo.telematics.pad.MessagePad
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,12 +26,11 @@ import mogo.telematics.pad.MessagePad
|
|||||||
object MoGoLocationDispatcher :
|
object MoGoLocationDispatcher :
|
||||||
IMoGoChassisGnssListener,
|
IMoGoChassisGnssListener,
|
||||||
IMoGoObuLocationWGS84Listener,
|
IMoGoObuLocationWGS84Listener,
|
||||||
AMapLocationListener {
|
IGaoDeMapLocationListener {
|
||||||
|
|
||||||
private const val TAG = "MoGoLocationManager"
|
private const val TAG = "MoGoLocationManager"
|
||||||
|
|
||||||
private var mCityCode: String? = null
|
private var mCityCode: String? = null
|
||||||
private var mapLocation: AMapLocation? = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 最后一次工控机GNSS返回更新的位置
|
* 最后一次工控机GNSS返回更新的位置
|
||||||
@@ -54,33 +48,10 @@ object MoGoLocationDispatcher :
|
|||||||
private var lastGaoDeLocation: MogoLocation = MogoLocation()
|
private var lastGaoDeLocation: MogoLocation = MogoLocation()
|
||||||
|
|
||||||
fun initListener() {
|
fun initListener() {
|
||||||
// 高德SDK隐私政策
|
|
||||||
AMapLocationClient.updatePrivacyShow(Utils.getApp(), true, true)
|
|
||||||
AMapLocationClient.updatePrivacyAgree(Utils.getApp(), true)
|
|
||||||
|
|
||||||
try {
|
|
||||||
val mLocationClient = AMapLocationClient(Utils.getApp())
|
|
||||||
|
|
||||||
//初始化定位参数
|
|
||||||
//声明mLocationOption对象
|
|
||||||
val mLocationOption = AMapLocationClientOption()
|
|
||||||
//设置定位监听
|
|
||||||
mLocationClient.setLocationListener(this)
|
|
||||||
//设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
|
|
||||||
mLocationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
|
|
||||||
//设置定位间隔,单位毫秒,默认为2000ms
|
|
||||||
mLocationOption.interval = 1000
|
|
||||||
//设置定位参数
|
|
||||||
mLocationClient.setLocationOption(mLocationOption)
|
|
||||||
// 启动定位监听
|
|
||||||
mLocationClient.startLocation()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化监听订阅工控机位置信息
|
// 初始化监听订阅工控机位置信息
|
||||||
CallerChassisGnssListenerManager.addListener(TAG, this)
|
CallerChassisGnssListenerManager.addListener(TAG, this)
|
||||||
CallerObuLocationWGS84ListenerManager.addListener(TAG, this)
|
CallerObuLocationWGS84ListenerManager.addListener(TAG, this)
|
||||||
|
CallerGaoDeMapLocationListenerManager.addListener(TAG, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChassisGnss(gnssInfo: MessagePad.GnssInfo) {
|
override fun onChassisGnss(gnssInfo: MessagePad.GnssInfo) {
|
||||||
@@ -88,13 +59,13 @@ object MoGoLocationDispatcher :
|
|||||||
lastGnssLocation.gnssInfo = gnssInfo
|
lastGnssLocation.gnssInfo = gnssInfo
|
||||||
lastGnssLocation.lastReceiveTime = TimeUtils.getNowMills()
|
lastGnssLocation.lastReceiveTime = TimeUtils.getNowMills()
|
||||||
// 将高德中的一些用于业务的数据进行融合,例如:CityCode、address等
|
// 将高德中的一些用于业务的数据进行融合,例如:CityCode、address等
|
||||||
mapLocation?.let {
|
lastGaoDeLocation.let {
|
||||||
//agps 高德
|
//agps 高德
|
||||||
//agps_rtk 高德-高精
|
//agps_rtk 高德-高精
|
||||||
lastGnssLocation.locType = 1000 // 定位类型为WGS84进行转译的坐标
|
lastGnssLocation.locType = 1000 // 定位类型为WGS84进行转译的坐标
|
||||||
lastGnssLocation.satellite = 4
|
lastGnssLocation.satellite = 4
|
||||||
|
|
||||||
lastGnssLocation.cityName = it.city
|
lastGnssLocation.cityName = it.cityName
|
||||||
lastGnssLocation.cityCode = it.cityCode
|
lastGnssLocation.cityCode = it.cityCode
|
||||||
lastGnssLocation.provider = it.provider
|
lastGnssLocation.provider = it.provider
|
||||||
lastGnssLocation.address = it.address
|
lastGnssLocation.address = it.address
|
||||||
@@ -128,79 +99,42 @@ object MoGoLocationDispatcher :
|
|||||||
MultiDisplayUtils.getOtherDisplay()
|
MultiDisplayUtils.getOtherDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 高德地图位置改变回调
|
* 高德地图位置改变回调
|
||||||
* @param aMapLocation 位置信息
|
* @param mogoLocation 位置信息
|
||||||
*/
|
*/
|
||||||
override fun onLocationChanged(aMapLocation: AMapLocation) {
|
override fun onMoGoLocationChanged(mogoLocation: MogoLocation) {
|
||||||
mapLocation = aMapLocation
|
// 更新GaoDe 信息
|
||||||
// 更新GNSS 信息
|
lastGaoDeLocation = mogoLocation
|
||||||
lastGaoDeLocation.lastReceiveTime = TimeUtils.getNowMills()
|
|
||||||
|
|
||||||
// 将高德中的一些用于业务的数据进行融合,例如:CityCode、address等
|
|
||||||
mapLocation?.let {
|
|
||||||
// 转换 GCJ02-->WGS84 坐标
|
|
||||||
val wgs84Location =
|
|
||||||
CoordinateTransform.GCJ02ToWGS84(it.longitude, it.latitude)
|
|
||||||
|
|
||||||
lastGaoDeLocation.longitude = wgs84Location[0]
|
|
||||||
lastGaoDeLocation.latitude = wgs84Location[1]
|
|
||||||
lastGaoDeLocation.heading = it.bearing.toDouble()
|
|
||||||
lastGaoDeLocation.gnssSpeed = it.speed
|
|
||||||
lastGaoDeLocation.altitude = it.altitude
|
|
||||||
lastGaoDeLocation.satelliteTime = it.time
|
|
||||||
lastGaoDeLocation.lastReceiveTime = TimeUtils.getNowMills()
|
|
||||||
|
|
||||||
lastGaoDeLocation.locType = 1 // 定位类型为高德坐标(网路或者硬件定位)
|
|
||||||
lastGaoDeLocation.satellite = 4
|
|
||||||
|
|
||||||
lastGaoDeLocation.cityName = it.city
|
|
||||||
lastGaoDeLocation.cityCode = it.cityCode
|
|
||||||
lastGaoDeLocation.provider = it.provider
|
|
||||||
lastGaoDeLocation.address = it.address
|
|
||||||
lastGaoDeLocation.district = it.district
|
|
||||||
lastGaoDeLocation.province = it.province
|
|
||||||
lastGaoDeLocation.adCode = it.adCode
|
|
||||||
lastGaoDeLocation.locationDetail = it.locationDetail
|
|
||||||
lastGaoDeLocation.poiName = it.poiName
|
|
||||||
lastGaoDeLocation.aoiName = it.aoiName
|
|
||||||
lastGaoDeLocation.street = it.street
|
|
||||||
lastGaoDeLocation.streetNum = it.streetNum
|
|
||||||
lastGaoDeLocation.description = it.description
|
|
||||||
lastGaoDeLocation.buildingId = it.buildingId
|
|
||||||
lastGaoDeLocation.floor = it.floor
|
|
||||||
lastGaoDeLocation.errorCode = it.errorCode
|
|
||||||
lastGaoDeLocation.errorInfo = it.errorInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算最后一次工控机同步的定位是否超时,如果超时则切换为高德地图定位,暂定超过30秒需要切换
|
// 计算最后一次工控机同步的定位是否超时,如果超时则切换为高德地图定位,暂定超过30秒需要切换
|
||||||
if (1 == FunctionBuildConfig.gpsProvider) {
|
if (1 == FunctionBuildConfig.gpsProvider) {
|
||||||
if (TimeUtils.getNowMills() - lastGnssLocation.lastReceiveTime > 30000) {
|
if (TimeUtils.getNowMills() - lastGnssLocation.lastReceiveTime > 10000) {
|
||||||
syncGaoDeLocation()
|
syncGaoDeLocation()
|
||||||
}
|
}
|
||||||
} else if (2 == FunctionBuildConfig.gpsProvider) {
|
} else if (2 == FunctionBuildConfig.gpsProvider) {
|
||||||
if (TimeUtils.getNowMills() - lastOBULocation.lastReceiveTime > 30000) {
|
if (TimeUtils.getNowMills() - lastOBULocation.lastReceiveTime > 10000) {
|
||||||
syncGaoDeLocation()
|
syncGaoDeLocation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 本地SP缓存城市Code
|
// 本地SP缓存城市Code
|
||||||
val cityCode = aMapLocation.cityCode
|
val cityCode = mogoLocation.cityCode
|
||||||
if (cityCode != null && cityCode.isNotEmpty()) {
|
if (cityCode != null && cityCode.isNotEmpty()) {
|
||||||
mCityCode = aMapLocation.cityCode
|
mCityCode = mogoLocation.cityCode
|
||||||
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
||||||
.putString(SharedPrefsConstants.LOCATION_CITY_CODE, cityCode)
|
.putString(SharedPrefsConstants.LOCATION_CITY_CODE, cityCode)
|
||||||
|
|
||||||
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
||||||
.putString(
|
.putString(
|
||||||
SharedPrefsConstants.LOCATION_LATITUDE,
|
SharedPrefsConstants.LOCATION_LATITUDE,
|
||||||
aMapLocation.latitude.toString()
|
mogoLocation.latitude.toString()
|
||||||
)
|
)
|
||||||
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
||||||
.putString(
|
.putString(
|
||||||
SharedPrefsConstants.LOCATION_LONGITUDE,
|
SharedPrefsConstants.LOCATION_LONGITUDE,
|
||||||
aMapLocation.longitude.toString()
|
mogoLocation.longitude.toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,13 +170,13 @@ object MoGoLocationDispatcher :
|
|||||||
lastOBULocation.lastReceiveTime = TimeUtils.getNowMills()
|
lastOBULocation.lastReceiveTime = TimeUtils.getNowMills()
|
||||||
|
|
||||||
// 将高德中的一些用于业务的数据进行融合,例如:CityCode、address等
|
// 将高德中的一些用于业务的数据进行融合,例如:CityCode、address等
|
||||||
mapLocation?.let {
|
lastGaoDeLocation.let {
|
||||||
//agps 高德
|
//agps 高德
|
||||||
//agps_rtk 高德-高精
|
//agps_rtk 高德-高精
|
||||||
lastOBULocation.locType = 1000 // 定位类型为WGS84进行转译的坐标
|
lastOBULocation.locType = 1000 // 定位类型为WGS84进行转译的坐标
|
||||||
lastOBULocation.satellite = 4
|
lastOBULocation.satellite = 4
|
||||||
|
|
||||||
lastOBULocation.cityName = it.city
|
lastOBULocation.cityName = it.cityName
|
||||||
lastOBULocation.cityCode = it.cityCode
|
lastOBULocation.cityCode = it.cityCode
|
||||||
lastOBULocation.provider = it.provider
|
lastOBULocation.provider = it.provider
|
||||||
lastOBULocation.address = it.address
|
lastOBULocation.address = it.address
|
||||||
@@ -274,4 +208,5 @@ object MoGoLocationDispatcher :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,5 +14,5 @@ interface IGaoDeMapLocationListener {
|
|||||||
*
|
*
|
||||||
* @param location 新定位点
|
* @param location 新定位点
|
||||||
*/
|
*/
|
||||||
fun onLocationChanged(location: MogoLocation, from: Int, isGps: Boolean)
|
fun onMoGoLocationChanged(location: MogoLocation)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.mogo.eagle.core.function.call.map
|
||||||
|
|
||||||
|
import com.mogo.eagle.core.data.map.MogoLocation
|
||||||
|
import com.mogo.eagle.core.function.api.map.listener.IGaoDeMapLocationListener
|
||||||
|
import com.mogo.eagle.core.function.call.base.CallerBase
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高德地图定位监听
|
||||||
|
*/
|
||||||
|
object CallerGaoDeMapLocationListenerManager : CallerBase<IGaoDeMapLocationListener>() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高德位置改变监听
|
||||||
|
*/
|
||||||
|
@Synchronized
|
||||||
|
fun invokeMoGoLocationChanged(location: MogoLocation) {
|
||||||
|
M_LISTENERS.forEach {
|
||||||
|
val tag = it.key
|
||||||
|
val listener = it.value
|
||||||
|
listener.onMoGoLocationChanged(location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
package com.mogo.map.location;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.amap.api.location.AMapLocation;
|
|
||||||
import com.amap.api.location.AMapLocationClient;
|
|
||||||
import com.amap.api.location.AMapLocationClientOption;
|
|
||||||
import com.amap.api.location.AMapLocationListener;
|
|
||||||
import com.mogo.commons.AbsMogoApplication;
|
|
||||||
import com.mogo.commons.constants.SharedPrefsConstants;
|
|
||||||
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 封装高德地图通过设备GPS获取到的位置信息,频率1s一次,坐标系为CJC20
|
|
||||||
* 这里的数据仅用于非高精度业务
|
|
||||||
*/
|
|
||||||
public class GDLocationClient implements AMapLocationListener, IMogoGDLocationClient {
|
|
||||||
|
|
||||||
private volatile static GDLocationClient gdLocationClient;
|
|
||||||
private static final byte[] obj = new byte[0];
|
|
||||||
|
|
||||||
public static GDLocationClient getInstance(Context context) {
|
|
||||||
if (gdLocationClient == null) {
|
|
||||||
synchronized (obj) {
|
|
||||||
if (gdLocationClient == null) {
|
|
||||||
gdLocationClient = new GDLocationClient(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return gdLocationClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
//声明LocationClient对象
|
|
||||||
private AMapLocationClient mLocationClient;
|
|
||||||
private String mCityCode;
|
|
||||||
private AMapLocation mapLocation;
|
|
||||||
|
|
||||||
private GDLocationClient(Context context) {
|
|
||||||
AMapLocationClient.updatePrivacyShow(context, true, true);
|
|
||||||
AMapLocationClient.updatePrivacyAgree(context, true);
|
|
||||||
try {
|
|
||||||
mLocationClient = new AMapLocationClient(context);
|
|
||||||
|
|
||||||
//初始化定位参数
|
|
||||||
//声明mLocationOption对象
|
|
||||||
AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
|
|
||||||
//设置定位监听
|
|
||||||
mLocationClient.setLocationListener(this);
|
|
||||||
//设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
|
|
||||||
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
|
|
||||||
//设置定位间隔,单位毫秒,默认为2000ms
|
|
||||||
mLocationOption.setInterval(1000);
|
|
||||||
//设置定位参数
|
|
||||||
mLocationClient.setLocationOption(mLocationOption);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() {
|
|
||||||
if (mLocationClient != null) {
|
|
||||||
mLocationClient.startLocation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
if (mLocationClient != null) {
|
|
||||||
mLocationClient.stopLocation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLocationChanged(AMapLocation aMapLocation) {
|
|
||||||
if (aMapLocation != null) {
|
|
||||||
mapLocation = aMapLocation;
|
|
||||||
String cityCode = aMapLocation.getCityCode();
|
|
||||||
if (cityCode != null && !cityCode.isEmpty()) {
|
|
||||||
mCityCode = aMapLocation.getCityCode();
|
|
||||||
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
|
||||||
.putString(SharedPrefsConstants.LOCATION_CITY_CODE, cityCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLastCityCode() {
|
|
||||||
return mCityCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getLastLat() {
|
|
||||||
return mapLocation != null ? mapLocation.getLatitude() : 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getLastLon() {
|
|
||||||
return mapLocation != null ? mapLocation.getLongitude() : 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package com.mogo.map.location
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.amap.api.location.AMapLocation
|
||||||
|
import com.amap.api.location.AMapLocationClient
|
||||||
|
import com.amap.api.location.AMapLocationClientOption
|
||||||
|
import com.amap.api.location.AMapLocationListener
|
||||||
|
import com.mogo.commons.AbsMogoApplication
|
||||||
|
import com.mogo.commons.constants.SharedPrefsConstants
|
||||||
|
import com.mogo.eagle.core.data.map.MogoLocation
|
||||||
|
import com.mogo.eagle.core.function.call.map.CallerGaoDeMapLocationListenerManager
|
||||||
|
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
|
||||||
|
import com.mogo.eagle.core.utilcode.util.CoordinateTransform
|
||||||
|
import com.mogo.eagle.core.utilcode.util.TimeUtils
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装高德地图通过设备GPS获取到的位置信息,频率1s一次,坐标系为CJC20
|
||||||
|
* 这里的数据仅用于非高精度业务
|
||||||
|
*/
|
||||||
|
class GDLocationClient private constructor(context: Context) : AMapLocationListener,
|
||||||
|
IMogoGDLocationClient {
|
||||||
|
//声明LocationClient对象
|
||||||
|
private lateinit var mLocationClient: AMapLocationClient
|
||||||
|
private var mCityCode: String = ""
|
||||||
|
private var mapLocation: AMapLocation? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后一次高德定位返回的位置信息
|
||||||
|
*/
|
||||||
|
private var lastGaoDeLocation: MogoLocation = MogoLocation()
|
||||||
|
|
||||||
|
init {
|
||||||
|
AMapLocationClient.updatePrivacyShow(context, true, true)
|
||||||
|
AMapLocationClient.updatePrivacyAgree(context, true)
|
||||||
|
try {
|
||||||
|
mLocationClient = AMapLocationClient(context)
|
||||||
|
|
||||||
|
//初始化定位参数
|
||||||
|
//声明mLocationOption对象
|
||||||
|
val mLocationOption = AMapLocationClientOption()
|
||||||
|
//设置定位监听
|
||||||
|
mLocationClient.setLocationListener(this)
|
||||||
|
//设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
|
||||||
|
mLocationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
|
||||||
|
//设置定位间隔,单位毫秒,默认为2000ms
|
||||||
|
mLocationOption.interval = 1000
|
||||||
|
//设置定位参数
|
||||||
|
mLocationClient.setLocationOption(mLocationOption)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun start() {
|
||||||
|
if (mLocationClient != null) {
|
||||||
|
mLocationClient.startLocation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
if (mLocationClient != null) {
|
||||||
|
mLocationClient.stopLocation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLocationChanged(aMapLocation: AMapLocation) {
|
||||||
|
// 更新GNSS 信息
|
||||||
|
lastGaoDeLocation.lastReceiveTime = TimeUtils.getNowMills()
|
||||||
|
|
||||||
|
// 将高德中的一些用于业务的数据进行融合,例如:CityCode、address等
|
||||||
|
mapLocation?.let {
|
||||||
|
// 转换 GCJ02-->WGS84 坐标
|
||||||
|
val wgs84Location =
|
||||||
|
CoordinateTransform.GCJ02ToWGS84(it.longitude, it.latitude)
|
||||||
|
|
||||||
|
lastGaoDeLocation.longitude = wgs84Location[0]
|
||||||
|
lastGaoDeLocation.latitude = wgs84Location[1]
|
||||||
|
lastGaoDeLocation.heading = it.bearing.toDouble()
|
||||||
|
lastGaoDeLocation.gnssSpeed = it.speed
|
||||||
|
lastGaoDeLocation.altitude = it.altitude
|
||||||
|
lastGaoDeLocation.satelliteTime = it.time
|
||||||
|
lastGaoDeLocation.lastReceiveTime = TimeUtils.getNowMills()
|
||||||
|
|
||||||
|
lastGaoDeLocation.locType = 1 // 定位类型为高德坐标(网路或者硬件定位)
|
||||||
|
lastGaoDeLocation.satellite = 4
|
||||||
|
|
||||||
|
lastGaoDeLocation.cityName = it.city
|
||||||
|
lastGaoDeLocation.cityCode = it.cityCode
|
||||||
|
lastGaoDeLocation.provider = it.provider
|
||||||
|
lastGaoDeLocation.address = it.address
|
||||||
|
lastGaoDeLocation.district = it.district
|
||||||
|
lastGaoDeLocation.province = it.province
|
||||||
|
lastGaoDeLocation.adCode = it.adCode
|
||||||
|
lastGaoDeLocation.locationDetail = it.locationDetail
|
||||||
|
lastGaoDeLocation.poiName = it.poiName
|
||||||
|
lastGaoDeLocation.aoiName = it.aoiName
|
||||||
|
lastGaoDeLocation.street = it.street
|
||||||
|
lastGaoDeLocation.streetNum = it.streetNum
|
||||||
|
lastGaoDeLocation.description = it.description
|
||||||
|
lastGaoDeLocation.buildingId = it.buildingId
|
||||||
|
lastGaoDeLocation.floor = it.floor
|
||||||
|
lastGaoDeLocation.errorCode = it.errorCode
|
||||||
|
lastGaoDeLocation.errorInfo = it.errorInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回掉给监听者
|
||||||
|
CallerGaoDeMapLocationListenerManager.invokeMoGoLocationChanged(lastGaoDeLocation)
|
||||||
|
|
||||||
|
mapLocation = aMapLocation
|
||||||
|
val cityCode = aMapLocation.cityCode
|
||||||
|
if (cityCode != null && !cityCode.isEmpty()) {
|
||||||
|
mCityCode = aMapLocation.cityCode
|
||||||
|
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp())
|
||||||
|
.putString(SharedPrefsConstants.LOCATION_CITY_CODE, cityCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getLastCityCode(): String {
|
||||||
|
return mCityCode
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getLastLat(): Double {
|
||||||
|
return if (mapLocation != null) mapLocation!!.latitude else 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getLastLon(): Double {
|
||||||
|
return if (mapLocation != null) mapLocation!!.longitude else 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Volatile
|
||||||
|
private var gdLocationClient: GDLocationClient? = null
|
||||||
|
private val obj = ByteArray(0)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getInstance(context: Context): GDLocationClient? {
|
||||||
|
if (gdLocationClient == null) {
|
||||||
|
synchronized(obj) {
|
||||||
|
if (gdLocationClient == null) {
|
||||||
|
gdLocationClient = GDLocationClient(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gdLocationClient
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user