android - 一个api给出的高坐标

标签 android google-maps latitude-longitude

在我的 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/

相关文章:

c#获取位置高度

java - 自动删除 EditText 任何文本的前导空格?

javascript - 谷歌地图 V3 : Pass drag event on marker to map

android - 如何使用不同的经纬度值绘制路线?

javascript - 谷歌地图标记管理器 : Cannot call method substr of undefined

java - 如何获取边界框的坐标

安卓聊天应用开发

java - 有没有办法找到页面上的所有 View.GONE 元素?

android - 如何在 android 中以编程方式应用低音效果

latitude-longitude - 经度/纬度到四元数