代码冲突
This commit is contained in:
@@ -67,7 +67,10 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
|
||||
val errorCode = it.locType
|
||||
mCurrentLocation = it
|
||||
mLocationLayer.setPosition(it.latitude, it.longitude, it.radius)
|
||||
Log.e("qj", "location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}")
|
||||
Log.e(
|
||||
"qj",
|
||||
"location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}"
|
||||
)
|
||||
|
||||
getCurrentNiLocation()?.let { it1 ->
|
||||
mContext.lifecycleScope.launch {
|
||||
@@ -212,6 +215,7 @@ private class MyLocationListener(callback: (BDLocation) -> Unit) : BDAbstractLoc
|
||||
val call = callback;
|
||||
override fun onReceiveLocation(location: BDLocation) {
|
||||
call(location)
|
||||
Log.e("jingo", "定位结果:速度=" + location.speed +" 方向=" + location.direction)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.navinfo.collect.library.utils;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.locationtech.jts.algorithm.distance.DistanceToPoint;
|
||||
import org.locationtech.jts.algorithm.distance.PointPairDistance;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
@@ -14,6 +19,7 @@ import org.locationtech.jts.io.WKTReader;
|
||||
import org.locationtech.jts.operation.linemerge.LineMerger;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.map.Map;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -416,7 +422,7 @@ public class GeometryTools {
|
||||
Geometry startGeo = createGeometry(startGeoPoint);
|
||||
Geometry endGeo = createGeometry(endGeoPoint);
|
||||
double d = startGeo.distance(endGeo);
|
||||
return convertDistanceToDegree(d,startGeoPoint.getLatitude());
|
||||
return convertDistanceToDegree(d, startGeoPoint.getLatitude());
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -589,6 +595,21 @@ public class GeometryTools {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<GeoPoint> getGeoPoints(Geometry geometry) {
|
||||
List<GeoPoint> list = null;
|
||||
if (geometry != null) {
|
||||
Coordinate[] coordinates = geometry.getCoordinates();
|
||||
if (coordinates != null && coordinates.length > 0) {
|
||||
list = new ArrayList<GeoPoint>();
|
||||
for (Coordinate coor : coordinates) {
|
||||
list.add(new GeoPoint(coor.y, coor.x));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static Coordinate[] getCoordinates(String str) {
|
||||
Coordinate[] coordinates = null;
|
||||
if (Check.isEmpty(str))
|
||||
@@ -1294,6 +1315,8 @@ public class GeometryTools {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public enum SNAP_TYPE {
|
||||
/**
|
||||
* 像素
|
||||
@@ -1327,7 +1350,7 @@ public class GeometryTools {
|
||||
}
|
||||
|
||||
public static boolean isCheckError(double lon, double lat) {
|
||||
if(lon==0||lat==0){
|
||||
if (lon == 0 || lat == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1377,8 +1400,10 @@ public class GeometryTools {
|
||||
|
||||
static class Check {
|
||||
public static boolean isEmpty(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return true;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1446,7 +1471,7 @@ public class GeometryTools {
|
||||
switch (unit) {
|
||||
case SNAP_PIXEL:
|
||||
org.oscim.core.Point p = new org.oscim.core.Point();
|
||||
fMap.viewport().toScreenPoint(gp,false, p);
|
||||
fMap.viewport().toScreenPoint(gp, false, p);
|
||||
GeoPoint gPLq = fMap.viewport().fromScreenPoint((float) p.x, (float) p.y);
|
||||
org.oscim.core.Point pL = new org.oscim.core.Point((p.x - distance), (p.y - distance));
|
||||
|
||||
@@ -1521,6 +1546,7 @@ public class GeometryTools {
|
||||
|
||||
/**
|
||||
* 计算距离
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
@@ -1573,10 +1599,68 @@ public class GeometryTools {
|
||||
* @return 对应的地理坐标系中的距离(单位:度)
|
||||
*/
|
||||
private static final double EARTH_RADIUS = 6371000.0;
|
||||
|
||||
public static double convertDistanceToDegree(double distance, double latitude) {
|
||||
double radianDistance = distance / EARTH_RADIUS;
|
||||
double radianLatitude = Math.toRadians(latitude);
|
||||
|
||||
double radianDegree = 2 * Math.asin(Math.sin(radianDistance / 2) / Math.cos(radianLatitude));
|
||||
return Math.toDegrees(radianDegree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 经纬度转墨卡托
|
||||
*/
|
||||
public static Coordinate geoPointToMercator(GeoPoint point) {
|
||||
Coordinate coordinate = new Coordinate();
|
||||
|
||||
double x = point.getLongitude() * 20037508.34 / 180;
|
||||
double y = Math.log(Math.tan((90 + point.getLatitude()) * Math.PI / 360)) / (Math.PI / 180);
|
||||
|
||||
y = y * 20037508.34 / 180;
|
||||
|
||||
coordinate.x = x;
|
||||
coordinate.y = y;
|
||||
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 墨卡托转经纬度
|
||||
*/
|
||||
public static GeoPoint mercatorToGeoPoint(Coordinate coordinate) {
|
||||
GeoPoint point = null;
|
||||
double x = coordinate.x / 20037508.34 * 180;
|
||||
double y = coordinate.y / 20037508.34 * 180;
|
||||
|
||||
y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2);
|
||||
|
||||
point = new GeoPoint(y, x);
|
||||
return point;
|
||||
}
|
||||
|
||||
public static List<GeoPoint> pointToLineDistance(GeoPoint point, List<GeoPoint> pointList) {
|
||||
|
||||
Coordinate coordinate = geoPointToMercator(point);
|
||||
Coordinate[] cs = new Coordinate[pointList.size()];
|
||||
|
||||
for (int i = 0; i < pointList.size(); i++) {
|
||||
Coordinate c = geoPointToMercator(pointList.get(i));
|
||||
cs[i] = c;
|
||||
}
|
||||
GeometryFactory factory = new GeometryFactory();
|
||||
LineString lineString = factory.createLineString(cs);
|
||||
PointPairDistance pointPairDistance = new PointPairDistance();
|
||||
DistanceToPoint.computeDistance(
|
||||
lineString,
|
||||
coordinate,
|
||||
pointPairDistance
|
||||
);
|
||||
|
||||
List newPoints = new ArrayList<GeoPoint>();
|
||||
for (int i = 0; i < pointPairDistance.getCoordinates().length; i++) {
|
||||
newPoints.add(mercatorToGeoPoint(pointPairDistance.getCoordinate(i)));
|
||||
}
|
||||
return newPoints;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user