在我的 Android 应用程序中,我需要在 map 上显示一些点。 我从 API ( http://data.citedia.com/r1/parks) 获取点坐标。
但是,API 给出的坐标值很高:"geometry":{"type":"Point","coordinates":[-187178.15,6124340.9]}。 我的意思是经度在 -180 或 180 之间...
有人遇到过同样的问题吗?
最佳答案
好的,这就是我的做法: 下载 JavaProj-noawt 库(来自 http://www.java2s.com/Code/Jar/j/Downloadjavaproj106noawtjar.htm )或任何其他来源,它是适用于没有 AWT 类的 Android 的版本。
然后使用下面的代码:
public static double[] convertFromWebMercatorToLatLng(double x, double y) {
Projection googleProjection = getGoogleProjection();
Point2D.Double latLngPoint = new Point2D.Double();
latLngPoint = googleProjection.inverseTransform(new Point2D.Double(x, y), latLngPoint);
return new double[] { latLngPoint.x, latLngPoint.y };
}
private static final int mGoogleEPSG = 3785;
// Projection EPSG
private static Projection mGoogleProjectionSystem = null;
private static Projection getGoogleProjection() {
if (null == mGoogleProjectionSystem) {
mGoogleProjectionSystem = ProjectionFactory.getNamedPROJ4CoordinateSystem("epsg:" + mGoogleEPSG);
}
return mGoogleProjectionSystem;
}
您只需将这段代码放在“Util”类中,然后将其作为提供 x(水平)和 y(垂直)坐标的静态方法调用,将为您提供一个包含“0”的 x(经度)和在“1”纬度。
请注意,谷歌地图中的 LatLng 对象是“已切换”的,包含 (y,x) 而不是上述方法中的 (x,y)!
关于android - 一个api给出的高坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32546908/