This commit is contained in:
zhongchao
2022-11-10 16:54:26 +08:00
parent 5322d03ec1
commit 2156d2cd18
148 changed files with 147 additions and 19811 deletions

View File

@@ -13,24 +13,20 @@ public class ServiceConst {
*/
public static final String TYPE = "STRATEGY_REFRESH";
/**
* 刷新策略模块地址
*/
public static final String PATH_REFRESH_STRATEGY = "/strategy/refresh";
/**
* 卡片 用户数据
*/
public static final String CARD_TYPE_USER_DATA = "CARD_TYPE_USER_DATA";
/**
* 卡片 探路数据
*/
public static final String CARD_TYPE_ROAD_CONDITION = "CARD_TYPE_ROAD_CONDITION";
/**
* 卡片 新鲜事
*/
public static final String CARD_TYPE_NOVELTY = "CARD_TYPE_NOVELTY";
public static final int ONLINE_SEARCH_LIMIT = 20;
public static final int ONLINE_SEARCH_RADIUS = 2_000;
}

View File

@@ -0,0 +1,156 @@
package com.mogo.commons.utils;
import static java.lang.Math.PI;
import android.util.Pair;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020/4/14 1:02 PM
* desc : 计算车辆驾驶方向的工具类
* version: 1.0
*/
public class DrivingDirectionUtils {
public static long getDegreeOfCar2Poi2(double x1, double y1, double x2, double y2, double x1_angle) {
Pair<Double, Double> newPoint = calculateNewPoint(x1, y1, x1_angle, 10);
if (newPoint != null) {
double angle = getAngle(x1, y1, newPoint.first, newPoint.second, x2, y2);
return Math.round(angle + 0.5);
}
return 0;
}
public static double distance(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow(x1 - x2, 2.0) + Math.pow(y1 - y2, 2.0));
}
public static double getAngle(double sx, double sy, double x1, double y1, double x2, double y2) {
x1 = x1 - sx;
y1 = y1 - sy;
x2 = x2 - sx;
y2 = y2 - sy;
double product = x1 * x2 + y1 * y2;
double radians = Math.acos(product / (Math.sqrt(Math.pow(x1, 2.0) + Math.pow(y1, 2.0)) * Math.sqrt(Math.pow(x2, 2.0) + Math.pow(y2, 2.0))));
return Math.toDegrees(radians);
}
public static Pair<Double, Double> calculateNewPoint(double x, double y, double angle, double distance) {
if (distance == 0) {
return null;
}
double radian = Math.toRadians(angle);
double radianCandle = Math.toRadians(90.0 - angle);
double nX = x + distance * Math.sin(radian) / 100000.0;
double nY = y + distance * Math.sin(radianCandle) / 100000.0;
return Pair.create(nX, nY);
}
/**
* 计算车辆行驶方向 与 poi点到车辆的连线 间的夹角
*
* @param carLon 车辆位置 lon
* @param carLat 车辆位置 lat
* @param poiLon poi 位置 lon
* @param poiLat poi 位置 lat
* @param carAngle 车辆行驶方向
* @return
*/
public static int getDegreeOfCar2Poi(double carLon, double carLat, double poiLon, double poiLat, int carAngle) {
int poiAngle = 0;
// 以子午线作为y轴 计算两点的余切 再将余切值转化为角度
double _angle = Math.atan2(Math.abs(carLon - poiLon), Math.abs(carLat - poiLat)) * (180 / PI);
if (poiLon > carLon) {
// poi 在 车辆位置的第1象限
if (poiLat > carLat) {
poiAngle = (int) _angle;
}
// poi 在 车辆位置的第2象限
else {
poiAngle = 180 - (int) _angle;
}
} else {
// poi 在 车辆位置的第3象限
if (poiLat < carLat) {
poiAngle = (int) _angle + 180;
}
// poi 在 车辆位置的第4象限
else {
poiAngle = 360 - (int) _angle;
}
}
return calculationAngle(poiAngle, carAngle);
}
/**
* 计算两个行驶方向间的夹角 计算结果小于180度
*
* @param angle0
* @param angle1
* @return
*/
public static int calculationAngle(int angle0, int angle1) {
// 获取两方向间夹角
int angle = Math.abs(angle0 - angle1);
if (angle > 180) {
int minAngle = Math.min(angle0, angle1);
int maxAngle = Math.max(angle0, angle1);
return 180 - Math.abs(minAngle + 180 - maxAngle);
} else {
return angle;
}
}
/**
* 计算车辆行驶方向角度,起点&终点经纬度
*
* @param carLat 车辆位置 lat
* @param carLon 车辆位置 lon
* @param poiLat poi 位置 lat
* @param poiLon poi 位置 lon
*/
public static int getCarAngle(double carLat, double carLon, double poiLat, double poiLon) {
int poiAngle = 0;
// 以子午线作为y轴 计算两点的余切 再将余切值转化为角度
double _angle = Math.atan2(Math.abs(carLon - poiLon), Math.abs(carLat - poiLat)) * (180 / PI);
if (poiLon > carLon) {
// poi 在 车辆位置的第1象限
if (poiLat > carLat) {
poiAngle = (int) _angle;
}
// poi 在 车辆位置的第2象限
else {
poiAngle = 180 - (int) _angle;
}
} else {
// poi 在 车辆位置的第3象限
if (poiLat < carLat) {
poiAngle = (int) _angle + 180;
}
// poi 在 车辆位置的第4象限
else {
poiAngle = 360 - (int) _angle;
}
}
if (poiAngle >= 355) {
poiAngle = 0;
}
return poiAngle;
}
/**
* 计算连两个角度差值
*
* @param angle1 角度1
* @param angle2 角度2
* @return 差值
*/
public static double getAngleDiff(double angle1, double angle2) {
// 两个角度差值较小
return 180 - Math.abs(Math.abs(angle1 - angle2) - 180);
}
}

View File

@@ -1,149 +0,0 @@
package com.mogo.commons.utils;
import java.text.DecimalFormat;
/**
* 莫顿编码
*
* @author linyang
* @since 2020.07.09
*/
public class MortonCode {
/**
* morton 转 经纬度 时的中间常量
*/
private static final long NDS_180_DEGREES = 0x7fffffff;
/**
* morton 转 经纬度 时的中间常量
*/
private static final long NDS_360_DEGREES = 4294967295L;
/**
* morton 转 经纬度 时的中间常量
*/
private static final long NDS_90_DEGREES = 0x3fffffff;
/**
* 经纬度转 morton 时的中间常量
*/
private static final double RULE_MORTON = Math.pow( 2, 32 ) / 360;
/**
* morton 转 经纬度 时的中间常量
*/
private static final double RULE_MORTON_TO_LONLAT = 360.0 / Math.pow( 2, 32 );
/**
* @param lon
* @param lat
* @return
*/
public static long wrapEncodeMorton( Double lon, Double lat ) {
DecimalFormat decimalFormat = new DecimalFormat( "#.######" );
return encodeMorton( Double.valueOf( decimalFormat.format( lon ) ),
Double.valueOf( decimalFormat.format( lat ) ) );
}
/**
* 编码 morton code
*
* @param lon
* @param lat
* @return
*/
public static long encodeMorton( Double lon, Double lat ) {
Long bit = 1L;
long mortonCode = 0L;
long x = ( long ) ( lon * RULE_MORTON );
long y = ( long ) ( lat * RULE_MORTON );
if ( y < 0 ) {
y += 0x7FFFFFFF;
}
y = y << 1;
for ( int i = 0; i < 32; i++ ) {
// x-part
mortonCode = mortonCode | ( x & bit );
x = x << 1;
bit = bit << 1;
// y-part
mortonCode = mortonCode | ( y & bit );
y = y << 1;
bit = bit << 1;
}
return mortonCode;
}
/**
* 将莫顿码解码为坐标
*
* @param mortonCode
* @return
*/
public static double[] decodeMorton( long mortonCode ) {
long[] midPoint = mortonCodeToCoord( mortonCode );
normalizeCoord( midPoint );
double[] point = new double[2];
// 将经纬度长整数转化为 浮点类型
point[0] = midPoint[0] * RULE_MORTON_TO_LONLAT;
point[1] = midPoint[1] * RULE_MORTON_TO_LONLAT;
return point;
}
/**
* 莫顿码分别拆解为 编码后的经纬度长整数
*
* @param mortonCode
* @return
*/
private static long[] mortonCodeToCoord( long mortonCode ) {
long bit = 1L;
long[] longPoint = new long[2];
for ( int i = 0; i < 32; i++ ) {
longPoint[0] |= mortonCode & bit;
mortonCode >>= 1;
longPoint[1] |= mortonCode & bit;
bit <<= 1;
}
return longPoint;
}
/**
* 对编码后的经纬度长整数进行解码
*
* @param midPoint
*/
private static void normalizeCoord( long[] midPoint ) {
// if x > 180 degrees, then subtract 360 degrees
if ( midPoint[0] > NDS_180_DEGREES ) {
midPoint[0] -=
NDS_360_DEGREES + 1; // add 1 because 0 must be counted as well
} else if ( midPoint[0] < -NDS_180_DEGREES ) // if x < 180 , x += 360
{
midPoint[0] +=
NDS_360_DEGREES + 1; // add 1 because 0 must be counted as well
}
// if y > 90 degrees, then subtract 180 degrees
if ( midPoint[1] > NDS_90_DEGREES ) {
midPoint[1] -=
NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well
} else if ( midPoint[1] < -NDS_90_DEGREES ) // if y < 90, y += 180
{
midPoint[1] +=
NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well
}
return;
}
public static void main( String[] args ) {
System.out.println( encodeMorton( 116.39584, 39.98152 ) );
}
}

View File

@@ -0,0 +1,53 @@
package com.mogo.commons.utils;
import com.mogo.eagle.core.data.map.MogoLatLng;
/**
* @author liujing
* @description 描述
* @since: 2021/4/13
*/
public class Trigonometric {
private final static double radius_b = 6378137;//大半径
private final static double radius_s = 6356725;//小半径
private static double mRadLo;
private static double mRadLa;
private static double Ec;
private static double Ed;
/**
* 计算两点间的角度
*/
public static double getAngle(double lon1, double lat1, double lon2,
double lat2) {
double fLat = Math.PI * (lat1) / 180.0;
double fLng = Math.PI * (lon1) / 180.0;
double tLat = Math.PI * (lat2) / 180.0;
double tLng = Math.PI * (lon2) / 180.0;
double degree = (Math.atan2(Math.sin(tLng - fLng) * Math.cos(tLat), Math.cos(fLat) * Math.sin(tLat) -
Math.sin(fLat) * Math.cos(tLat) * Math.cos(tLng - fLng))) * 180.0 / Math.PI;
if (degree >= 0) {
return degree;
} else {
return 360 + degree;
}
}
/**
* 根据角度获取指定距离点的经纬度
*/
public static MogoLatLng getNewLocation(double lon, double lat, double distance, double angle) {
mRadLo = lon * Math.PI / 180.;
mRadLa = lat * Math.PI / 180.;
Ec = radius_s + (radius_b - radius_s) * (90. - lat) / 90;
Ed = Ec * Math.cos(mRadLa);
double dx = distance * Math.sin(Math.toRadians(angle));
double dy = distance * Math.cos(Math.toRadians(angle));
double lon_new = (dx / Ed + mRadLo) * 180. / Math.PI;
double lat_new = (dy / Ec + mRadLa) * 180. / Math.PI;
return new MogoLatLng(lat_new, lon_new);
}
}

View File

@@ -1,63 +0,0 @@
package com.mogo.commons.utils;
import android.content.Context;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.Scroller;
import java.lang.reflect.Field;
public
/**
* @author congtaowang
* @since 2020/10/19
*
* 描述
*/
class ViewPagerSpeedScroller extends Scroller {
private int mFixedDuration = 1500;
public ViewPagerSpeedScroller( Context context ) {
super( context );
}
public ViewPagerSpeedScroller( Context context, Interpolator interpolator ) {
super( context, interpolator );
}
public ViewPagerSpeedScroller( Context context, Interpolator interpolator, boolean flywheel ) {
super( context, interpolator, flywheel );
}
@Override
public void startScroll( int startX, int startY, int dx, int dy ) {
startScroll( startX, startY, dx, dy, mFixedDuration );
}
@Override
public void startScroll( int startX, int startY, int dx, int dy, int duration ) {
super.startScroll( startX, startY, dx, dy, mFixedDuration );
}
public void setFixedDuration( int duration ) {
this.mFixedDuration = duration;
}
public static void attach( Context context, Object pager, int duration ) {
try {
Field filed = pager.getClass().getDeclaredField( "mScroller" );
filed.setAccessible( true );
ViewPagerSpeedScroller scroller = new ViewPagerSpeedScroller( context, new DecelerateInterpolator() );
scroller.setFixedDuration( duration );
filed.set( pager, scroller );
Field field = pager.getClass().getDeclaredField( "mTouchSlop" );
field.setAccessible( true );
field.setInt( pager, 4 );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}