@@ -1,26 +1,21 @@
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.constants.SharedPrefsConstants
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.enums.DataSourceType
import com.mogo.eagle.core.data.map.MogoLocation
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.call.autopilot.CallerChassisGnssListenerManager
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.map.CallerGaoDeMapLocationListenerManager
import com.mogo.eagle.core.function.call.obu.CallerObuLocationWGS84ListenerManager
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.TimeUtils
import com.mogo.eagle.core.utilcode.util.Utils
import com.mogo.support.obu.model.MogoObuHvBasicsData
import mogo.telematics.pad.MessagePad
/**
@@ -31,12 +26,11 @@ import mogo.telematics.pad.MessagePad
object MoGoLocationDispatcher :
IMoGoChassisGnssListener ,
IMoGoObuLocationWGS84Listener ,
A MapLocationListener {
IGaoDe MapLocationListener {
private const val TAG = " MoGoLocationManager "
private var mCityCode : String ? = null
private var mapLocation : AMapLocation ? = null
/**
* 最后一次工控机GNSS返回更新的位置
@@ -54,33 +48,10 @@ object MoGoLocationDispatcher :
private var lastGaoDeLocation : MogoLocation = MogoLocation ( )
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 )
CallerObuLocationWGS84ListenerManager . addListener ( TAG , this )
CallerGaoDeMapLocationListenerManager . addListener ( TAG , this )
}
override fun onChassisGnss ( gnssInfo : MessagePad . GnssInfo ) {
@@ -88,13 +59,13 @@ object MoGoLocationDispatcher :
lastGnssLocation . gnssInfo = gnssInfo
lastGnssLocation . lastReceiveTime = TimeUtils . getNowMills ( )
// 将高德中的一些用于业务的数据进行融合, 例如: CityCode、address等
map Location? .let {
lastGaoDe Location .let {
//agps 高德
//agps_rtk 高德-高精
lastGnssLocation . locType = 1000 // 定位类型为WGS84进行转译的坐标
lastGnssLocation . satellite = 4
lastGnssLocation . cityName = it . city
lastGnssLocation . cityName = it . cityName
lastGnssLocation . cityCode = it . cityCode
lastGnssLocation . provider = it . provider
lastGnssLocation . address = it . address
@@ -128,79 +99,42 @@ object MoGoLocationDispatcher :
MultiDisplayUtils . getOtherDisplay ( )
}
/**
* 高德地图位置改变回调
* @param aMap Location 位置信息
* @param mogo Location 位置信息
*/
override fun onLocationChanged ( aMap Location: AMap Location) {
mapLocation = 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
}
override fun onMoGo LocationChanged ( mogo Location: Mogo Location) {
// 更新GaoDe 信息
lastGaoDeLocation = mogoLocation
// 计算最后一次工控机同步的定位是否超时,如果超时则切换为高德地图定位,暂定超过30秒需要切换
if ( 1 == FunctionBuildConfig . gpsProvider ) {
if ( TimeUtils . getNowMills ( ) - lastGnssLocation . lastReceiveTime > 3 0000) {
if ( TimeUtils . getNowMills ( ) - lastGnssLocation . lastReceiveTime > 1 0000) {
syncGaoDeLocation ( )
}
} else if ( 2 == FunctionBuildConfig . gpsProvider ) {
if ( TimeUtils . getNowMills ( ) - lastOBULocation . lastReceiveTime > 3 0000) {
if ( TimeUtils . getNowMills ( ) - lastOBULocation . lastReceiveTime > 1 0000) {
syncGaoDeLocation ( )
}
}
// 本地SP缓存城市Code
val cityCode = aMap Location. cityCode
val cityCode = mogo Location. cityCode
if ( cityCode != null && cityCode . isNotEmpty ( ) ) {
mCityCode = aMap Location. cityCode
mCityCode = mogo Location. cityCode
SharedPrefsMgr . getInstance ( AbsMogoApplication . getApp ( ) )
. putString ( SharedPrefsConstants . LOCATION _CITY _CODE , cityCode )
SharedPrefsMgr . getInstance ( AbsMogoApplication . getApp ( ) )
. putString (
SharedPrefsConstants . LOCATION _LATITUDE ,
aMap Location. latitude . toString ( )
mogo Location. latitude . toString ( )
)
SharedPrefsMgr . getInstance ( AbsMogoApplication . getApp ( ) )
. putString (
SharedPrefsConstants . LOCATION _LONGITUDE ,
aMap Location. longitude . toString ( )
mogo Location. longitude . toString ( )
)
}
@@ -236,13 +170,13 @@ object MoGoLocationDispatcher :
lastOBULocation . lastReceiveTime = TimeUtils . getNowMills ( )
// 将高德中的一些用于业务的数据进行融合, 例如: CityCode、address等
map Location? .let {
lastGaoDe Location .let {
//agps 高德
//agps_rtk 高德-高精
lastOBULocation . locType = 1000 // 定位类型为WGS84进行转译的坐标
lastOBULocation . satellite = 4
lastOBULocation . cityName = it . city
lastOBULocation . cityName = it . cityName
lastOBULocation . cityCode = it . cityCode
lastOBULocation . provider = it . provider
lastOBULocation . address = it . address
@@ -274,4 +208,5 @@ object MoGoLocationDispatcher :
)
}
}
}