地图地理坐标(lat, lng)到地图(x, y)

时间:2021-03-18 21:17:04

I have the geo-coordinates (latidute & longitude) of some cities and would like to get the x,y coordinates so can plot them into a map.

我有一些城市的地理坐标(纬度和经度),我想要得到x,y坐标以便把它们绘制成地图。

The map is a standart one, just like http://www.wordtravels.com/images/map/Spain/Fuerteventura_map.jpg for example.

这张地图是标准的,就像http://www.wordtravels.com/images/mapain/fuerteventura_map.jpg那样。

I tried several formular I found, but none seems to really work :(. Simple javascript code or ruby would be best :)

我试了好几种找到的形式,但没有一种似乎真的有效。简单的javascript代码或ruby最好:)

5 个解决方案

#1


2  

in addition to the above answers, there is the open source proj4js library which performs transforms between various map projections. it is used internally by OpenLayers for this kind of thing, and supports a number of popular projections and coordinate systems.

除了上面的答案,还有一个开放源码的proj4js库,它在各种映射之间执行转换。它在内部被OpenLayers用于这类事情,并且支持许多流行的投影和坐标系统。

#2


3  

There are many ways to approach this problem with varying degrees of precision. However, they all boil down to performing a projection that corresponds with that of your map.

有许多方法可以用不同的精度来解决这个问题。但是,它们都可以归结为执行与地图对应的投影。

If you know that your map is of the Mercator projection variety, then the lat/long coordinates can simply be treated as X/Y, scaled and translated appropriately. That is, you would find a simple ax+b and cy+d that do the job.

如果你知道你的地图是墨卡托投影的多样性,那么lat/long坐标可以简单的被当作X/Y,按比例缩放和翻译。也就是说,你会找到一个简单的ax+b和cy+d。

If your map is not Mercator-projection (as it probably isn't if it tries to get the scale consistent, as this one appears to do) then your best bet is to assume it's an "earth-tangent" projection. (This works out OK for small landmasses.) In that case, you need to first project the Lat/Long into a three-dimensional coordinate system.

如果你的地图不是梅尔卡托投影(如果它试图使比例尺保持一致,就像这幅图看起来的那样),那么你最好的选择就是假设它是一个“地球切线”投影。(这对于小地块来说是可行的。)在这种情况下,您需要首先将Lat/Long投影到一个三维坐标系中。

z=sin(lat)
x=cos(lat)*sin(long)
y=cos(lat)*cos(long)

Positive z points to the north pole. Positive y points to 0, 0, and positive x points to lat 0 long 90 (east) and positive lat/long are north and east. Of course you must convert to radians first.

正z指向北极。正的y点为0,0,正x点为lat 0 90(东)和正lat/long为北部和东部。当然,你必须先转换成弧度。

All of this assumes a spherical Earth, which isn't exactly true but it's close enough unless you're firing long-range mortar rounds.

所有这些都假设了一个球形的地球,这并不完全正确,但它足够近,除非你发射远程迫击炮。

Anyway, once you have your XYZ, then you'll need to rotate and scale for the map. To rotate around the Z axis, just subtract the base longitude before you project into three dimensions. Do this to center your map on zero-longitude for easiest math.

不管怎样,一旦你有了XYZ,你就需要旋转和缩放地图。若要绕Z轴旋转,只需在投射到三维空间之前减去基准经度即可。这样做是为了把你的地图放在零经度的地图上,做最简单的数学题。

Once you've done this, you'll only need to rotate the globe forward until your original map is face-front. Do this with a 2-d rotation in the y-z axis. Use http://en.wikipedia.org/wiki/Coordinate_rotations_and_reflections to figure that part out.

一旦你这样做了,你只需要旋转地球仪向前直到你的原始地图是正面的。在y-z轴上进行二维旋转。使用http://en.wikipedia.org/wiki/coordinate_rotations_and_reflection来理解这一部分。

Finally, your x,z coordinates are going to line up pretty well with your map's x,y coordinates, for an appropriate scale/translate as described earlier.

最后,你的x z坐标将会和你的地图的x y坐标很好地对齐,以达到前面描述的合适的比例/转换。

#3


1  

Use the Google Maps API, you can overlay your jpg on the map and position it correctly.

使用谷歌地图API,您可以在地图上覆盖您的jpg并正确定位它。

Here is an example http://code.google.com/apis/maps/documentation/javascript/examples/overlay-hideshow.html

这里有一个例子http://code.google.com/apis/maps/documentation/javascript/examples/overlay-hideshow.html

and here is the api page about overlays http://code.google.com/apis/maps/documentation/javascript/overlays.html

这是关于覆盖http://code.google.com/apis/maps/documentation/javascript/overlays.html的api页面

#4


1  

perhaps this will help, i've done a implementation for the US using just javascript.

也许这将会有所帮助,我已经用javascript完成了对美国的实现。

demo/code: http://the55.net/_11/sketch/us_map

演示/代码:http://the55.net/_11/sketch/us_map

#5


0  

You won't find it easy unless you're working on a very small scale (and close to the Equator). Wikipedia's Geographic coordinate system is a good start...

除非你在一个很小的范围内(并且靠近赤道),否则你不会轻易发现它。*的地理坐标系统是一个好的开始。

The easier path could be to make use of something like web mapping and stick with your latitudes and longitudes.

更简单的方法可能是利用web mapping之类的东西,坚持你的纬度和经度。

#1


2  

in addition to the above answers, there is the open source proj4js library which performs transforms between various map projections. it is used internally by OpenLayers for this kind of thing, and supports a number of popular projections and coordinate systems.

除了上面的答案,还有一个开放源码的proj4js库,它在各种映射之间执行转换。它在内部被OpenLayers用于这类事情,并且支持许多流行的投影和坐标系统。

#2


3  

There are many ways to approach this problem with varying degrees of precision. However, they all boil down to performing a projection that corresponds with that of your map.

有许多方法可以用不同的精度来解决这个问题。但是,它们都可以归结为执行与地图对应的投影。

If you know that your map is of the Mercator projection variety, then the lat/long coordinates can simply be treated as X/Y, scaled and translated appropriately. That is, you would find a simple ax+b and cy+d that do the job.

如果你知道你的地图是墨卡托投影的多样性,那么lat/long坐标可以简单的被当作X/Y,按比例缩放和翻译。也就是说,你会找到一个简单的ax+b和cy+d。

If your map is not Mercator-projection (as it probably isn't if it tries to get the scale consistent, as this one appears to do) then your best bet is to assume it's an "earth-tangent" projection. (This works out OK for small landmasses.) In that case, you need to first project the Lat/Long into a three-dimensional coordinate system.

如果你的地图不是梅尔卡托投影(如果它试图使比例尺保持一致,就像这幅图看起来的那样),那么你最好的选择就是假设它是一个“地球切线”投影。(这对于小地块来说是可行的。)在这种情况下,您需要首先将Lat/Long投影到一个三维坐标系中。

z=sin(lat)
x=cos(lat)*sin(long)
y=cos(lat)*cos(long)

Positive z points to the north pole. Positive y points to 0, 0, and positive x points to lat 0 long 90 (east) and positive lat/long are north and east. Of course you must convert to radians first.

正z指向北极。正的y点为0,0,正x点为lat 0 90(东)和正lat/long为北部和东部。当然,你必须先转换成弧度。

All of this assumes a spherical Earth, which isn't exactly true but it's close enough unless you're firing long-range mortar rounds.

所有这些都假设了一个球形的地球,这并不完全正确,但它足够近,除非你发射远程迫击炮。

Anyway, once you have your XYZ, then you'll need to rotate and scale for the map. To rotate around the Z axis, just subtract the base longitude before you project into three dimensions. Do this to center your map on zero-longitude for easiest math.

不管怎样,一旦你有了XYZ,你就需要旋转和缩放地图。若要绕Z轴旋转,只需在投射到三维空间之前减去基准经度即可。这样做是为了把你的地图放在零经度的地图上,做最简单的数学题。

Once you've done this, you'll only need to rotate the globe forward until your original map is face-front. Do this with a 2-d rotation in the y-z axis. Use http://en.wikipedia.org/wiki/Coordinate_rotations_and_reflections to figure that part out.

一旦你这样做了,你只需要旋转地球仪向前直到你的原始地图是正面的。在y-z轴上进行二维旋转。使用http://en.wikipedia.org/wiki/coordinate_rotations_and_reflection来理解这一部分。

Finally, your x,z coordinates are going to line up pretty well with your map's x,y coordinates, for an appropriate scale/translate as described earlier.

最后,你的x z坐标将会和你的地图的x y坐标很好地对齐,以达到前面描述的合适的比例/转换。

#3


1  

Use the Google Maps API, you can overlay your jpg on the map and position it correctly.

使用谷歌地图API,您可以在地图上覆盖您的jpg并正确定位它。

Here is an example http://code.google.com/apis/maps/documentation/javascript/examples/overlay-hideshow.html

这里有一个例子http://code.google.com/apis/maps/documentation/javascript/examples/overlay-hideshow.html

and here is the api page about overlays http://code.google.com/apis/maps/documentation/javascript/overlays.html

这是关于覆盖http://code.google.com/apis/maps/documentation/javascript/overlays.html的api页面

#4


1  

perhaps this will help, i've done a implementation for the US using just javascript.

也许这将会有所帮助,我已经用javascript完成了对美国的实现。

demo/code: http://the55.net/_11/sketch/us_map

演示/代码:http://the55.net/_11/sketch/us_map

#5


0  

You won't find it easy unless you're working on a very small scale (and close to the Equator). Wikipedia's Geographic coordinate system is a good start...

除非你在一个很小的范围内(并且靠近赤道),否则你不会轻易发现它。*的地理坐标系统是一个好的开始。

The easier path could be to make use of something like web mapping and stick with your latitudes and longitudes.

更简单的方法可能是利用web mapping之类的东西,坚持你的纬度和经度。