修改定位无效问题

This commit is contained in:
qiji4215
2023-07-18 17:08:07 +08:00
parent 53275472f4
commit 0378378dec
3 changed files with 15 additions and 32 deletions

View File

@@ -270,21 +270,10 @@ class MainViewModel @Inject constructor(
*/ */
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
private fun initLocation() { private fun initLocation() {
//用于定位点存储到数据库 //用于定位点存储到数据库
viewModelScope.launch(Dispatchers.Default) { viewModelScope.launch(Dispatchers.Default) {
//用于定位点捕捉道路 //用于定位点捕捉道路
mapController.locationLayerHandler.niLocationFlow.collectLatest { location ->
if (!isSelectRoad() && !GeometryTools.isCheckError(
location.longitude, location.latitude
)
) {
captureLink(
GeoPoint(
location.latitude, location.longitude
)
)
}
}
mapController.locationLayerHandler.niLocationFlow.collect { location -> mapController.locationLayerHandler.niLocationFlow.collect { location ->
//过滤掉无效点 //过滤掉无效点
@@ -335,23 +324,23 @@ class MainViewModel @Inject constructor(
} }
} }
} }
} }
//用于定位点捕捉道路
viewModelScope.launch(Dispatchers.Default) { viewModelScope.launch(Dispatchers.Default) {
//用于定位点捕捉道路
mapController.locationLayerHandler.niLocationFlow.collectLatest { location -> mapController.locationLayerHandler.niLocationFlow.collectLatest { location ->
if (!isSelectRoad() && !GeometryTools.isCheckError( if (!isSelectRoad() && !GeometryTools.isCheckError(
location.longitude, location.longitude, location.latitude
location.latitude
) )
) captureLink( ) {
captureLink(
GeoPoint( GeoPoint(
location.latitude, location.latitude, location.longitude
location.longitude
) )
) )
} }
} }
}
//显示轨迹图层 //显示轨迹图层
mapController.layerManagerHandler.showNiLocationLayer() mapController.layerManagerHandler.showNiLocationLayer()

View File

@@ -30,7 +30,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
// //
// } // }
val niLocationFlow = MutableSharedFlow<NiLocation>(3) val niLocationFlow = MutableSharedFlow<NiLocation>(5)
init { init {
///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组 ///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组
@@ -67,18 +67,12 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
val errorCode = it.locType val errorCode = it.locType
mCurrentLocation = it mCurrentLocation = it
mLocationLayer.setPosition(it.latitude, it.longitude, it.radius) mLocationLayer.setPosition(it.latitude, it.longitude, it.radius)
// Log.e( Log.e("qj", "location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}")
// "qj",
// "location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}"
// )
// if (niLocationListener != null) {
getCurrentNiLocation()?.let { it1 -> getCurrentNiLocation()?.let { it1 ->
mContext.lifecycleScope.launch(Dispatchers.Default) { mContext.lifecycleScope.launch {
niLocationFlow.emit(it1) niLocationFlow.emit(it1)
} }
// }// niLocationListener.call(it1) }
} }
//第一次定位成功显示当前位置 //第一次定位成功显示当前位置
if (this.bFirst) { if (this.bFirst) {

View File

@@ -504,7 +504,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
0 -> { 0 -> {
//角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可 //角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可
//角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可 //角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可
if (direction != 0.0) { if (direction > 0.0) {
val symbolGpsTemp = val symbolGpsTemp =
MarkerSymbol(niLocationBitmap, MarkerSymbol.HotspotPlace.CENTER, false) MarkerSymbol(niLocationBitmap, MarkerSymbol.HotspotPlace.CENTER, false)
geoMarkerItem.marker = symbolGpsTemp geoMarkerItem.marker = symbolGpsTemp
@@ -519,7 +519,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
1 -> { 1 -> {
//角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可 //角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可
//角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可 //角度不为0时需要预先设置marker样式并进行角度设置否则使用图层默认的sym即可
if (direction != 0.0) { if (direction > 0.0) {
val symbolLidarTemp = val symbolLidarTemp =
MarkerSymbol(niLocationBitmap1, MarkerSymbol.HotspotPlace.CENTER, false) MarkerSymbol(niLocationBitmap1, MarkerSymbol.HotspotPlace.CENTER, false)
geoMarkerItem.marker = symbolLidarTemp geoMarkerItem.marker = symbolLidarTemp