如何在android中逆转这种数学转换

如何在android中逆转这种数学转换,android,google-maps,google-maps-android-api-2,coordinate-transformation,Android,Google Maps,Google Maps Android Api 2,Coordinate Transformation,我使用这段代码将谷歌地图坐标转换为自定义覆盖图上的X,Y系统。这将获取纬度、经度和缩放,并使用内置的自定义中心点将其转换为x、y。获得x,y并将其转换回纬度和经度的正确步骤是什么 static Double game_1_x = 1972.606; static Double game_1_y = 3817.044; static Double map_1_lng = 42.012002; static Double map_1_lat = 42.850185; static Double g

我使用这段代码将谷歌地图坐标转换为自定义覆盖图上的X,Y系统。这将获取纬度、经度和缩放,并使用内置的自定义中心点将其转换为x、y。获得x,y并将其转换回纬度和经度的正确步骤是什么

static Double game_1_x = 1972.606;
static Double game_1_y = 3817.044;
static Double map_1_lng = 42.012002;
static Double map_1_lat = 42.850185;

static Double game_2_x = -1210.765;
static Double game_2_y = -3443.753;
static Double map_2_lng = -49.922088;
static Double map_2_lat = -83.293854;

public static String convertToXY(String lat, String lon, float zoom) {

    int mapSize = 0;

    if (zoom == 2.0f) {
        mapSize = 1024;
    } else if (zoom == 3.0f) {
        mapSize = 2048;
    } else if (zoom == 4.0f) {
        mapSize = 4096;
    } else if (zoom == 5.0f) {
        mapSize = 8192;
    }

    Double LAT = Double.valueOf(lat);
    Double LON = Double.valueOf(lon);

    // get marker x value
    Double markerLon = (LON + 180) * (mapSize / 360);

    // convert Lat to Radians
    Double markerLatRad = LAT * Math.PI / 180;

    // get marker y value
    Double mercN = Math.log(Math.tan((Math.PI / 4) + (markerLatRad / 2)));
    Double markerLat = (mapSize / 2) - (mapSize * mercN / (2 * Math.PI));

    // get map 1 x value
    Double m1lng = (map_1_lng + 180) * (mapSize / 360);
    // get map 2 x value
    Double m2lng = (map_2_lng + 180) * (mapSize / 360);

    // convert Lat to Radians
    Double m1LatRad = map_1_lat * Math.PI / 180;
    Double m2LatRad = map_2_lat * Math.PI / 180;

    // get map 1 y value
    Double mercNm1y = Math.log(Math.tan((Math.PI / 4) + (m1LatRad / 2)));
    Double m1lat = (mapSize / 2) - (mapSize * mercNm1y / (2 * Math.PI));
    // get map 2 y value
    Double mercNm2y = Math.log(Math.tan((Math.PI / 4) + (m2LatRad / 2)));
    Double m2lat = (mapSize / 2) - (mapSize * mercNm2y / (2 * Math.PI));


    Double X = game_1_x + (markerLon - m1lng) * (game_1_x - game_2_x) / (m1lng - m2lng);
    Double Y = game_1_y + (markerLat - m1lat) * (game_1_y - game_2_y) / (m1lat - m2lat);

    return String.valueOf(X) + "," + String.valueOf(Y);
}

看看这是否是您需要的:

mMap = mMapView.getMap();
mMap.getProjection().fromScreenLocation(Point p)
反过来说

mMap.getProjection().toScreenLocation(LatLng l)

我不打算做数学运算,但是让触摸通过你的覆盖层,从地图上获取纬度和经度怎么样。我想让用户使用x,y输入一个自定义标记,然后检索lat LNGS应该添加的,我使用的是API v2,这是不可用的