完成了Acc on首次选中最近的在线车辆
This commit is contained in:
@@ -4,10 +4,13 @@ import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.marker.MogoMarkersHandler;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.common.entity.MarkerCarChat;
|
||||
@@ -57,6 +60,8 @@ public class MarkerServiceHandler {
|
||||
private static IMogoNavi mNavi;
|
||||
private static IMogoMapUIController mMapUIController;
|
||||
|
||||
private static IMogoLocationClient mLocationClient;
|
||||
|
||||
private static IMogoStatusManager mMogoStatusManager;
|
||||
private static IMogoImageloader mImageloader;
|
||||
private static IMogoSocketManager mMogoSocketManager;
|
||||
@@ -66,7 +71,7 @@ public class MarkerServiceHandler {
|
||||
private static Context mContext;
|
||||
|
||||
// 第一次请求到地图的Marker数据
|
||||
private static boolean isFirstMarker;
|
||||
private static boolean isFirstMarker = true;
|
||||
|
||||
public static void init(final Context context) {
|
||||
mContext = context;
|
||||
@@ -81,6 +86,7 @@ public class MarkerServiceHandler {
|
||||
mMarkerManager = mMapService.getMarkerManager(context);
|
||||
mNavi = mMapService.getNavi(context);
|
||||
mMapUIController = mMapService.getMapUIController();
|
||||
mLocationClient = mMapService.getLocationClient(context);
|
||||
mogoMarkerClickListener = new MoGoMarkerClickListener();
|
||||
|
||||
// 长连接
|
||||
@@ -95,7 +101,7 @@ public class MarkerServiceHandler {
|
||||
public void onMsgReceived(MarkerResponse response) {
|
||||
Logger.e(TAG, "======MarkerResponse:" + response);
|
||||
if (!getMogoStatusManager().isSearchUIShow() && !getMogoStatusManager().isV2XShow()) {
|
||||
isFirstMarker=true;
|
||||
isFirstMarker = true;
|
||||
drawMapMarker(response);
|
||||
}
|
||||
}
|
||||
@@ -283,7 +289,7 @@ public class MarkerServiceHandler {
|
||||
markerCardResult.getDataType().contains(ServiceConst.CARD_TYPE_USER_DATA)) {
|
||||
getMarkerManager().removeMarkers(ServiceConst.CARD_TYPE_USER_DATA);
|
||||
getMogoCardManager().switch2(ServiceConst.CARD_TYPE_USER_DATA);
|
||||
|
||||
isFirstMarker = true;
|
||||
} else {
|
||||
// 清空所有地图上绘制的Marker
|
||||
getMarkerManager().removeMarkers();
|
||||
@@ -311,6 +317,8 @@ public class MarkerServiceHandler {
|
||||
}
|
||||
|
||||
if (onlineCarList != null) {
|
||||
IMogoMarker nearlyMogoMarker = null;
|
||||
double nearlyDistance = Double.MAX_VALUE;
|
||||
for (MarkerOnlineCar markerOnlineCar : onlineCarList) {
|
||||
MarkerLocation markerLocation = markerOnlineCar.getLocation();
|
||||
|
||||
@@ -321,9 +329,36 @@ public class MarkerServiceHandler {
|
||||
markerShowEntity.setTextContent(markerOnlineCar.getUserInfo().getUserName());
|
||||
markerShowEntity.setIconUrl(markerOnlineCar.getUserInfo().getUserHead());
|
||||
|
||||
drawMapMarker(markerShowEntity);
|
||||
IMogoMarker iMogoMarker = drawMapMarker(markerShowEntity);
|
||||
// 计算在线车辆距离当前车辆的距离,每次都与最后一次距离最近的进行比较,保留距离最近的车辆,进行卡片展示
|
||||
try {
|
||||
double calculateDistance = Utils.calculateLineDistance(
|
||||
new MogoLatLng(markerLocation.getLat(), markerLocation.getLat()),
|
||||
new MogoLatLng(mLocationClient.getLastKnowLocation().getLatitude(), mLocationClient.getLastKnowLocation().getLongitude())
|
||||
);
|
||||
|
||||
// 进行比较,保留最近的一个数据
|
||||
if (calculateDistance < nearlyDistance) {
|
||||
nearlyMogoMarker = iMogoMarker;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
fillNumberTrackEventBody(array, 3, onlineCarList.size());
|
||||
|
||||
try {
|
||||
// 在ACC on 之后第一次获取到了在线车辆数据,选中最近的一个Marker
|
||||
if (isFirstMarker) {
|
||||
if (nearlyMogoMarker != null) {
|
||||
MogoMarkersHandler.getInstance().onMarkerClicked(nearlyMogoMarker);
|
||||
isFirstMarker = false;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (exploreWayList != null) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.mogo.module.service;
|
||||
|
||||
import com.amap.api.maps.AMapException;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
|
||||
/**
|
||||
@@ -12,8 +10,15 @@ import com.mogo.map.MogoLatLng;
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static float calculateLineDistance( MogoLatLng point1, MogoLatLng point2 ) {
|
||||
if ( point1 != null && point2 != null ) {
|
||||
/**
|
||||
* 距离半径计算方式
|
||||
*
|
||||
* @param point1 点一坐标
|
||||
* @param point2 点二坐标
|
||||
* @return 两坐标的距离 单位:米(M)
|
||||
*/
|
||||
public static float calculateLineDistance(MogoLatLng point1, MogoLatLng point2) {
|
||||
if (point1 != null && point2 != null) {
|
||||
try {
|
||||
double var2 = point1.lng;
|
||||
double var4 = point1.lat;
|
||||
@@ -23,14 +28,14 @@ public class Utils {
|
||||
var4 *= 0.01745329251994329D;
|
||||
var6 *= 0.01745329251994329D;
|
||||
var8 *= 0.01745329251994329D;
|
||||
double var10 = Math.sin( var2 );
|
||||
double var12 = Math.sin( var4 );
|
||||
double var14 = Math.cos( var2 );
|
||||
double var16 = Math.cos( var4 );
|
||||
double var18 = Math.sin( var6 );
|
||||
double var20 = Math.sin( var8 );
|
||||
double var22 = Math.cos( var6 );
|
||||
double var24 = Math.cos( var8 );
|
||||
double var10 = Math.sin(var2);
|
||||
double var12 = Math.sin(var4);
|
||||
double var14 = Math.cos(var2);
|
||||
double var16 = Math.cos(var4);
|
||||
double var18 = Math.sin(var6);
|
||||
double var20 = Math.sin(var8);
|
||||
double var22 = Math.cos(var6);
|
||||
double var24 = Math.cos(var8);
|
||||
double[] var28 = new double[3];
|
||||
double[] var29 = new double[3];
|
||||
var28[0] = var16 * var14;
|
||||
@@ -39,8 +44,8 @@ public class Utils {
|
||||
var29[0] = var24 * var22;
|
||||
var29[1] = var24 * var18;
|
||||
var29[2] = var20;
|
||||
return ( float ) ( Math.asin( Math.sqrt( ( var28[0] - var29[0] ) * ( var28[0] - var29[0] ) + ( var28[1] - var29[1] ) * ( var28[1] - var29[1] ) + ( var28[2] - var29[2] ) * ( var28[2] - var29[2] ) ) / 2.0D ) * 1.27420015798544E7D );
|
||||
} catch ( Throwable var26 ) {
|
||||
return (float) (Math.asin(Math.sqrt((var28[0] - var29[0]) * (var28[0] - var29[0]) + (var28[1] - var29[1]) * (var28[1] - var29[1]) + (var28[2] - var29[2]) * (var28[2] - var29[2])) / 2.0D) * 1.27420015798544E7D);
|
||||
} catch (Throwable var26) {
|
||||
var26.printStackTrace();
|
||||
return 0.0F;
|
||||
}
|
||||
@@ -48,4 +53,9 @@ public class Utils {
|
||||
return 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
double calculateLineDistance = calculateLineDistance(new MogoLatLng(39.955533, 116.423262), new MogoLatLng(39.955385, 116.414604));
|
||||
System.out.println("距离点 calculateLineDistance:" + calculateLineDistance);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user