我对墨卡托投影有点问题,当我在纬度上尝试投影时,我得到了纳米值...
我的代码来自这个问题: ConvertLATLONGTOXY
private static List<Point2D.Double> LatLongConvertionToXY(List<GeoPoint> coordinates) {
List<Point2D.Double> xys = new ArrayList<Point2D.Double>();
/*MercatorProjection projection = new MercatorProjection();*/
Log.i("LATLONG2RAD", "Nouvelle conversion");
for (GeoPoint coordinate : coordinates) {
double latitude = Double.valueOf(coordinate.getLatitudeE6());
double longitude = Double.valueOf(coordinate.getLongitudeE6());
// convert to radian
latitude = latitude * Math.PI / 180;
longitude = longitude * Math.PI / 180;
Log.i("LATLONG2RAD", String.valueOf(latitude)+" : "+String.valueOf(longitude));
/*Point2D.Double d = projection.project(longitude,latitude,
new Point2D.Double());*/
Point2D.Double d=new Point2D.Double();
double QUARTERPI = Math.PI / 4.0;
d.x = longitude;
d.y = Math.log(Math.tan(QUARTERPI + 0.5 * latitude));
Log.i("PointLATLONG YX", String.valueOf(d.y)+" : "+String.valueOf(d.x));
xys.add(d);
}
return xys;
}
此返回值示例: 12-15 21:42:27.165:I / LATLONG2RAD(32629):Nouvelle转换
12-15 21:42:27.165:I / LATLONG2RAD(32629):LAT 782581.6732236275:LONG -10478.398323613315
12-15 21:42:27.165:I / LATLONG2RAD(32629):LAT 782581.6732236275:LONG -10478.398323613315
12-15 21:42:27.165:I / LATLONG2RAD(32629):LAT 782587.2931838189:LONG -10476.478461436123
12-15 21:42:27.165:I / LATLONG2RAD(32629):LAT 782571.9517396939:LONG -10476.478461436123
投影的返回值:
12-15 21:42:27.165:I / PointLATLONG YX(32629):NaN:-10478.398323613315
12-15 21:42:27.165:I / PointLATLONG YX(32629):NaN:-10478.398323613315
12-15 21:42:27.165:I / PointLATLONG YX(32629):NaN:-10476.478461436123
12-15 21:42:27.165:I / PointLATLONG YX(32629):1.7354151627839085:-10476.478461436123
答案 0 :(得分:0)
最后,JRowan我可以阅读代码,然后我使用投影mercator重试Java Map Library,我发现我的问题是osm geopoint的第一个到nan值我的值是微观度而不是双倍:< / p>
我的新代码:
private static List<Point2D.Double> LatLongConvertionToXY(List<GeoPoint> coordinates) {
List<Point2D.Double> xys = new ArrayList<Point2D.Double>();
MercatorProjection projection = new MercatorProjection();
Log.i("LATLONG2RAD", "New");
for (GeoPoint coordinate : coordinates) {
double latitude = Double.valueOf(coordinate.getLatitudeE6());
double longitude = Double.valueOf(coordinate.getLongitudeE6());
//to decimal
latitude=latitude / 1E6;
longitude=longitude / 1E6;
Log.i("LATLONG2RAD", "BEFORE RADIAN "+String.valueOf(latitude)+" : "+String.valueOf(longitude));
//convert to radian
latitude = latitude * Math.PI / 180;
longitude = longitude * Math.PI / 180;
//Log.i("LATLONG2RAD", String.valueOf(latitude)+" : "+String.valueOf(longitude));
Point2D.Double d = projection.project(longitude,latitude,
new Point2D.Double());
Log.i("LATLONG2RAD"," Y X "+ String.valueOf(d.y)+" : "+String.valueOf(d.x));
xys.add(d);
}
return xys;
}
预测似乎很好:
12-15 22:41:40.257:I / LATLONG2RAD(1138):Y X 0.8505407464143129:0.11730010582132741
12-15 22:41:40.267:I / LATLONG2RAD(1138):Y X 0.8506068875926396:0.11715522604011937
12-15 22:41:40.267:I / LATLONG2RAD(1138):Y X 0.8505923208133851:0.1172139738227415
12-15 22:41:40.267:I / LATLONG2RAD(1138):Y X 0.8505727537288554:0.1172139738227415
但现在另一个pb是交叉计算:
public static GeoPoint intersectionV1bis(List<GeoPoint> mGeoPoints) {
if (mGeoPoints.size() == 0 || mGeoPoints.size() > 4)
return null;
List<Point2D.Double> coordinates = LatLongConvertionToXY(mGeoPoints);
double x1 = coordinates.get(0).x;
double y1 = coordinates.get(0).y;
double x2 = coordinates.get(1).x;
double y2 = coordinates.get(1).y;
double x3 = coordinates.get(2).x;
double y3 = coordinates.get(2).y;
double x4 = coordinates.get(3).x;
double y4 = coordinates.get(3).y;
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (d == 0){
Log.i("INTERSECT V1","Segments parallels");
return null;
}
double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2)
* (x3 * y4 - y3 * x4))
/ d;
double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2)
* (x3 * y4 - y3 * x4))
/ d;
GeoPoint p = new GeoPoint(xi, yi);
Log.i("INTERSECT","xi long"+String.valueOf(xi)+" : yi lat"+String.valueOf(yi));
if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2)){
Log.i("INTERSECT V1","Not in segment 1");
return null;
}
if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4)){
Log.i("INTERSECT V1","Not in segment 2");
return null;
}
Log.i("INTERSECT","Intersection");
return p;
}
12-15 22:41:40.267:I / INTERSECT(1138):xi long0.11721397382272966:yi lat0.8505800677870533
在Open街道地图上,线段相交,但代码说不,我不明白为什么。点A和B是我的最后一个和新位置,C和D是点E的左右两点(通过按下第一个交叉点上的按钮定义,当前位置的轴承+90和-90),即在A和B之间。
我使用模拟器一直有相同的位置,但是当我尝试在A和B之间以及C和D之间的第2个交叉点计算E时,E不在C和D上