If i have a jpeg map with size sizeX, sizeY
如果我有一个大小为sizeX的jpeg地图,sizeY。
and some calibration points on the map (X, Y, Lon, Lat)
以及地图上的一些校准点(X, Y, Lon, Lat)
What would be the algorithm for calculating the corresponding XY point in the map with a given Longitude / Latitude pair?
用给定的经纬度对计算地图中相应的XY点的算法是什么?
7 个解决方案
#1
17
Here's what worked for me, without so much bs.
这是我的工作,没有那么多的b。
int x = (int) ((MAP_WIDTH/360.0) * (180 + lon));
int y = (int) ((MAP_HEIGHT/180.0) * (90 - lat));
The lat,lon coordinates were given to me by Android devices. So they should be in the same standard used by all Google Earth/Map products.
lat,lon坐标是由Android设备提供给我的。因此,它们应该与所有谷歌地球/地图产品所用的标准相同。
#2
9
If using the Equidistant Cylindrical Projection type map, here is what you need to do:
如果使用等距圆柱投影式地图,以下是你需要做的:
- Find the Latitude and longitude of your location tutorial here:
http://lifehacker.com/267361/how-to-find-latitude-and-longitude - 在这里找到位置教程的纬度和经度:http://lifehacker.com/267361/howto - Find - Latitude -longitude。
- Input that information into the following formulas:
x = (total width of image in px) * (180 + latitude) / 360
y = (total height of image in px) * (90 - longitude) / 180
note: when using negative longitude of latitude make sure to add or subtract the negative number i.e. +(-92) or -(-35) which would actually be -92 and +35
- 将这些信息输入以下公式:x =(总宽度的图像px)*(180 +纬度)/ 360 y =(总高度的图像在px)*(90 -经度)/ 180注意:当使用负经度纬度确保添加或减去负数即+(-92)-(-35)这将是-92和+ 35
- You now have your X and Y to plot on your image
More information can be found about this formula and the map type here:
http://www.progonos.com/furuti/MapProj/Dither/CartHow/HowER_W12/howER_W12.html#DeductionEquirectangular - 现在,您已经有了X和Y来在您的图像上绘制更多的信息,可以在这里找到关于这个公式和映射类型的信息:http://www.progonos.com/furuti/mapproj/dither/carthow/hower_w12/hower_w12/hower_w12.html #推导等矩形。
#3
8
There is plenty of information on the Internet about calculating the distance between two pairings of latitude and longitude. We're using those calculations on our public website and they are not trivial to understand/discuss (so I won't try to cover them here). That said, they are easy to implement.
互联网上有很多关于计算纬度和经度之间的距离的信息。我们在我们的公共网站上使用这些计算方法,它们并不容易理解/讨论(所以我不会试图在这里介绍它们)。也就是说,它们很容易实现。
Once you have a function that returns distance, you should be able to caculate the width and height of the map in terms of distance between the corners.
一旦你有了一个返回距离的函数,你就应该能够计算出地图的宽度和高度。
Then you can calculate the horizontal and vertical distance of your point from the top-left corner.
然后你可以计算你的点从左上角的水平和垂直距离。
Now you find out what ratio of the map's width is represented by the distance between the left side and your point, apply that ratio to the pixel width and you have the number of pixels between the left side and your point. Repeat for the y-axis.
现在你知道了地图宽度的比例是由左边和你的点之间的距离来表示的,把这个比值应用到像素宽度,你就得到了左边和你的点之间的像素个数。重复的轴。
(Pixels from left side) = (total width in pixels) * ((geocode distance between left and your point) / (geocode distance between left side and right side))
(左侧像素)=(像素的总宽度)*(左与点之间的geocode距离)/(左侧与右侧之间的geocode距离)
(Pixels from top) = (total height in pixels) * ((geocode distance between top and your point) / (geocode distance between top and bottom))
(像素)=(像素的总高度)*(顶部和你点之间的geocode距离)/(顶部和底部之间的geocode距离)
EDIT: As you research this further you will note that some solutions will present more accurate results than others due to the fact that you are approximating distance between two points on a spherical surface and mapping that on a flat surface. The accuracy decreases as the distance increases. Best advice to you is to try it out first and see if it meets your needs.
编辑:当你进一步研究这个问题时,你会注意到一些解决方案会比其他的解决方案更精确,因为你是在一个球面上的两个点之间近似的距离,并在平面上映射。随着距离的增加,准确度会降低。给你最好的建议是先试一试,看看它是否符合你的需要。
#4
7
This is fairly straight forward and simple.. let me explain how its possible.
这是相当直接和简单的。让我解释一下它的可能。
Latitude and Longitude are imaginary lines drawn on earth so that you can accurately pinpoint any location on the world . simply put they are the X and Y coords of a plane. Latitude is a vertical line running from north to south with its 90 deg at the north pole and -90deg at the south pole.
纬度和经度是在地球上画出的假想线,这样你就能准确地指出世界上的任何位置。简单地说,它们是平面的X和Y坐标。纬度是一条从北到南的垂直直线,在北极有90度,在南极有90度。
Longitude on the other hand is a horizontal line running east to south with -180deg in the west and 180deg in the east.
另一只手的经度是一条水平线,东向南,西至180deg,东向180度。
you can convert the latLng into pixel coords as by assuming that the width of the html container is the width of the world and the same applies to the the height.
您可以将latLng转换成像素坐标,假设html容器的宽度是世界的宽度,同样适用于高度。
Formula - Longitude - pixel
公式-经度-像素。
(givenLng*widthOfContainerElement)/360
where 360 is the total longitude in degrees
360度的经度是多少度?
Formula -Latitude - pixel
公式纬度-像素
(givenLat*heightOfContainerElement)/180
where 180 is the total latitude in degree
其中180度是多少度?
//Height is calculated from the bottom
you can find a working implementation of this formula here, on my website (it uses JavaScript only)
你可以在我的网站上找到这个公式的工作实现(只使用JavaScript)
http://www.learntby.me/javascript/latLngconversion.php
http://www.learntby.me/javascript/latLngconversion.php
let me know if you still need any clarifications.
如果你还需要澄清的话,请告诉我。
#5
5
There are many different map projection schemes. You would have to know which one(s) are used by your maps.
有许多不同的地图投影方案。你必须知道你的地图使用了哪一个。
For more information about map projection algorithms and forward/reverse mapping check out this link. It provides the formulas for a number of common projections.
有关地图投影算法和正向/反向映射的更多信息,请查看此链接。它为许多共同的预测提供了公式。
#6
1
Just make this(for Mercator projection map):
只要做这个(对于墨卡托投影地图):
extension UIView
{
func addLocation(coordinate: CLLocationCoordinate2D)
{
// max MKMapPoint values
let maxY = Double(267995781)
let maxX = Double(268435456)
let mapPoint = MKMapPointForCoordinate(coordinate)
let normalizatePointX = CGFloat(mapPoint.x / maxX)
let normalizatePointY = CGFloat(mapPoint.y / maxY)
let pointView = UIView(frame: CGRectMake(0, 0, 5, 5))
pointView.center = CGPointMake(normalizatePointX * frame.width, normalizatePointY * frame.height)
pointView.backgroundColor = UIColor.blueColor()
addSubview(pointView)
}
}
My simple project for adding coordinate on UIView: https://github.com/Glechik/MapCoordinateDrawer
我在UIView上添加坐标的简单项目:https://github.com/Glechik/MapCoordinateDrawer。
#7
1
<!DOCTYPE html>
<html>
<head>
<style>
#point{font-face:Arial; font-size:18px; color:#FFFF00; width:12px; height:12px;text-shadow: 2px 2px #000000}
#canvas {position: absolute; top: 0px; left: 0px; z-index: -2}
html,
body,
#canvas {
width: 100%;
height: 100%;
overflow: hidden;
margin: 0
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(window).on("load resize",function(e){
var w = $("#canvas").width();
var h = $("#canvas").height();
// New York, NY (https://maps.googleapis.com/maps/api/geocode/json?address=New%20York,%20NY)
var lat = 40.91525559999999;
var long = -73.70027209999999;
var x = ((w/360) * (180 + long)) - 9;
var y = ((h/180) * (90 - lat)) - 18;
$("#text").text('X:'+x+', Y:'+y);
$("#point").offset({ top: y, left: x });
});
</script>
</head>
<body>
<div id="text"></div>
<div id="point">▼</div>
<img id="canvas" border="0" src="http://friday.westnet.com/~crywalt/dymaxion_2003/earthmap10k.reduced.jpg">
</body>
</html>
#1
17
Here's what worked for me, without so much bs.
这是我的工作,没有那么多的b。
int x = (int) ((MAP_WIDTH/360.0) * (180 + lon));
int y = (int) ((MAP_HEIGHT/180.0) * (90 - lat));
The lat,lon coordinates were given to me by Android devices. So they should be in the same standard used by all Google Earth/Map products.
lat,lon坐标是由Android设备提供给我的。因此,它们应该与所有谷歌地球/地图产品所用的标准相同。
#2
9
If using the Equidistant Cylindrical Projection type map, here is what you need to do:
如果使用等距圆柱投影式地图,以下是你需要做的:
- Find the Latitude and longitude of your location tutorial here:
http://lifehacker.com/267361/how-to-find-latitude-and-longitude - 在这里找到位置教程的纬度和经度:http://lifehacker.com/267361/howto - Find - Latitude -longitude。
- Input that information into the following formulas:
x = (total width of image in px) * (180 + latitude) / 360
y = (total height of image in px) * (90 - longitude) / 180
note: when using negative longitude of latitude make sure to add or subtract the negative number i.e. +(-92) or -(-35) which would actually be -92 and +35
- 将这些信息输入以下公式:x =(总宽度的图像px)*(180 +纬度)/ 360 y =(总高度的图像在px)*(90 -经度)/ 180注意:当使用负经度纬度确保添加或减去负数即+(-92)-(-35)这将是-92和+ 35
- You now have your X and Y to plot on your image
More information can be found about this formula and the map type here:
http://www.progonos.com/furuti/MapProj/Dither/CartHow/HowER_W12/howER_W12.html#DeductionEquirectangular - 现在,您已经有了X和Y来在您的图像上绘制更多的信息,可以在这里找到关于这个公式和映射类型的信息:http://www.progonos.com/furuti/mapproj/dither/carthow/hower_w12/hower_w12/hower_w12.html #推导等矩形。
#3
8
There is plenty of information on the Internet about calculating the distance between two pairings of latitude and longitude. We're using those calculations on our public website and they are not trivial to understand/discuss (so I won't try to cover them here). That said, they are easy to implement.
互联网上有很多关于计算纬度和经度之间的距离的信息。我们在我们的公共网站上使用这些计算方法,它们并不容易理解/讨论(所以我不会试图在这里介绍它们)。也就是说,它们很容易实现。
Once you have a function that returns distance, you should be able to caculate the width and height of the map in terms of distance between the corners.
一旦你有了一个返回距离的函数,你就应该能够计算出地图的宽度和高度。
Then you can calculate the horizontal and vertical distance of your point from the top-left corner.
然后你可以计算你的点从左上角的水平和垂直距离。
Now you find out what ratio of the map's width is represented by the distance between the left side and your point, apply that ratio to the pixel width and you have the number of pixels between the left side and your point. Repeat for the y-axis.
现在你知道了地图宽度的比例是由左边和你的点之间的距离来表示的,把这个比值应用到像素宽度,你就得到了左边和你的点之间的像素个数。重复的轴。
(Pixels from left side) = (total width in pixels) * ((geocode distance between left and your point) / (geocode distance between left side and right side))
(左侧像素)=(像素的总宽度)*(左与点之间的geocode距离)/(左侧与右侧之间的geocode距离)
(Pixels from top) = (total height in pixels) * ((geocode distance between top and your point) / (geocode distance between top and bottom))
(像素)=(像素的总高度)*(顶部和你点之间的geocode距离)/(顶部和底部之间的geocode距离)
EDIT: As you research this further you will note that some solutions will present more accurate results than others due to the fact that you are approximating distance between two points on a spherical surface and mapping that on a flat surface. The accuracy decreases as the distance increases. Best advice to you is to try it out first and see if it meets your needs.
编辑:当你进一步研究这个问题时,你会注意到一些解决方案会比其他的解决方案更精确,因为你是在一个球面上的两个点之间近似的距离,并在平面上映射。随着距离的增加,准确度会降低。给你最好的建议是先试一试,看看它是否符合你的需要。
#4
7
This is fairly straight forward and simple.. let me explain how its possible.
这是相当直接和简单的。让我解释一下它的可能。
Latitude and Longitude are imaginary lines drawn on earth so that you can accurately pinpoint any location on the world . simply put they are the X and Y coords of a plane. Latitude is a vertical line running from north to south with its 90 deg at the north pole and -90deg at the south pole.
纬度和经度是在地球上画出的假想线,这样你就能准确地指出世界上的任何位置。简单地说,它们是平面的X和Y坐标。纬度是一条从北到南的垂直直线,在北极有90度,在南极有90度。
Longitude on the other hand is a horizontal line running east to south with -180deg in the west and 180deg in the east.
另一只手的经度是一条水平线,东向南,西至180deg,东向180度。
you can convert the latLng into pixel coords as by assuming that the width of the html container is the width of the world and the same applies to the the height.
您可以将latLng转换成像素坐标,假设html容器的宽度是世界的宽度,同样适用于高度。
Formula - Longitude - pixel
公式-经度-像素。
(givenLng*widthOfContainerElement)/360
where 360 is the total longitude in degrees
360度的经度是多少度?
Formula -Latitude - pixel
公式纬度-像素
(givenLat*heightOfContainerElement)/180
where 180 is the total latitude in degree
其中180度是多少度?
//Height is calculated from the bottom
you can find a working implementation of this formula here, on my website (it uses JavaScript only)
你可以在我的网站上找到这个公式的工作实现(只使用JavaScript)
http://www.learntby.me/javascript/latLngconversion.php
http://www.learntby.me/javascript/latLngconversion.php
let me know if you still need any clarifications.
如果你还需要澄清的话,请告诉我。
#5
5
There are many different map projection schemes. You would have to know which one(s) are used by your maps.
有许多不同的地图投影方案。你必须知道你的地图使用了哪一个。
For more information about map projection algorithms and forward/reverse mapping check out this link. It provides the formulas for a number of common projections.
有关地图投影算法和正向/反向映射的更多信息,请查看此链接。它为许多共同的预测提供了公式。
#6
1
Just make this(for Mercator projection map):
只要做这个(对于墨卡托投影地图):
extension UIView
{
func addLocation(coordinate: CLLocationCoordinate2D)
{
// max MKMapPoint values
let maxY = Double(267995781)
let maxX = Double(268435456)
let mapPoint = MKMapPointForCoordinate(coordinate)
let normalizatePointX = CGFloat(mapPoint.x / maxX)
let normalizatePointY = CGFloat(mapPoint.y / maxY)
let pointView = UIView(frame: CGRectMake(0, 0, 5, 5))
pointView.center = CGPointMake(normalizatePointX * frame.width, normalizatePointY * frame.height)
pointView.backgroundColor = UIColor.blueColor()
addSubview(pointView)
}
}
My simple project for adding coordinate on UIView: https://github.com/Glechik/MapCoordinateDrawer
我在UIView上添加坐标的简单项目:https://github.com/Glechik/MapCoordinateDrawer。
#7
1
<!DOCTYPE html>
<html>
<head>
<style>
#point{font-face:Arial; font-size:18px; color:#FFFF00; width:12px; height:12px;text-shadow: 2px 2px #000000}
#canvas {position: absolute; top: 0px; left: 0px; z-index: -2}
html,
body,
#canvas {
width: 100%;
height: 100%;
overflow: hidden;
margin: 0
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(window).on("load resize",function(e){
var w = $("#canvas").width();
var h = $("#canvas").height();
// New York, NY (https://maps.googleapis.com/maps/api/geocode/json?address=New%20York,%20NY)
var lat = 40.91525559999999;
var long = -73.70027209999999;
var x = ((w/360) * (180 + long)) - 9;
var y = ((h/180) * (90 - lat)) - 18;
$("#text").text('X:'+x+', Y:'+y);
$("#point").offset({ top: y, left: x });
});
</script>
</head>
<body>
<div id="text"></div>
<div id="point">▼</div>
<img id="canvas" border="0" src="http://friday.westnet.com/~crywalt/dymaxion_2003/earthmap10k.reduced.jpg">
</body>
</html>