如何在Android中使用自定义中心点将lat lng转换为xy

时间:2015-03-27 01:25:51

标签: android google-maps google-maps-api-2

我有谷歌地图。我在它上面放了一个tileOverlay(一个虚构的游戏世界)。游戏使用x,y坐标系。我需要将我所有的lat lng坐标转换为这个精确的x,y系统。

我在地图上选了两个点并从游戏中获得了真正的xy值。 然后从android地图得到了这两个点的lat lng。 然后使用了这段代码:

// First spot data
static Double game_1_x = 1972.606;
static Double game_1_y = 3817.044;
static Double map_1_lng = 42.108797;
static Double map_1_lat = 43.152977;

// second spot data
static Double game_2_x = -1154.11;
static Double game_2_y = -2715.203;
static Double map_2_lng = -48.3334;
static Double map_2_lat = -80.346344;

Double LAT = latFromMarker;
Double LON = lngFromMarker;

// this works
// all markers added with this equation fall on the correct longitude line
Double X = game_1_x + (LON - map_1_lng) * (game_1_x - game_2_x) / (map_1_lng - map_2_lng);

// this does not work
// markers added using this equation are always too far north or south of where they need to be
Double Y = game_1_y + (LAT - map_1_lat) * (game_1_y - game_2_y) / (map_1_lat - map_2_lat);

" y"转换无法正常工作是因为由于Google Maps API v2墨卡托投影,纬度线的间距不均匀。

我需要知道我需要做些什么来解释这种波动。我确定有一些先进的等式或其他东西,但我已经毫不费力地用谷歌搜索了几个小时并空手而归。

1 个答案:

答案 0 :(得分:0)

我认为你必须像这样做一些数学......

enter image description here

类似于cos(alpha) *R=r ......?

不是数学专业,也不擅长数学...... 所以你应该在math stack exchange

中提出这个问题

= - = - = - = - = - = - = OR = - = - = - = - = - = - =

因为你关心的是D:d

您可以使用computeDistanceBetween(LatLngFrom, LatLngTo)函数找到D:d,通过比较具有相同lng和不同lat的两对两点之间的距离。 (比如lng 0与lng 45相比,1度纬度有多长)

有关computeDistanceBetween的更多信息。