如何改变1米到像素的距离?像素、距离

2023-09-05 06:37:34 作者:波若波羅蜜

当我开发一个Android地图应用程序,我想提请其半径1米地图上的圆圈。正如你知,我不能画1米直接,我应该转换成1米到两个像素之间的距离取决于缩放级别。如何我将它转换,有什么API,我可以使用。

When I develop an Android map application, I want to draw a circle on the map whose radius is 1 meter. As you known, I can't draw 1 meter directly, I should convert 1 meter to the distance of two pixels depend on the zoom level. How to I convert it, is there anything API I can use.

Canvas.draw(X,Y,半径),什么样的价值,我应该把这个方法?

Canvas.draw(x, y, radius), what value should I put to this method ?

推荐答案

假设你的地图是谷歌地图,他们所使用的墨卡托投影,所以你需要使用的转换。 下墨卡托投影,即一个像素重新presents在米随纬度,因此,虽然一米是一个非常小的距离相对于地球半径的距离,纬度是重要的。

Assuming that your map is Google Maps, they use the Mercator projection, so you'd need to use that for the conversion. Under the Mercator projection, the distance that a pixel represents in meters varies with latitude, so while a meter is a very small distance compared to the Earth radius, latitude is important.

下面所有的例子是JavaScript,因此你可能需要翻译。

All the examples below are javascript, so you might need to translate them.

下面是坐标系的一般说明:

Here is a general explanation of the coordinate system:

的http://$c$c.google.com/apis/maps/documentation/javascript/maptypes.html#WorldCoordinates

此示例包含一个MercatorProjection对象,其中包括方法fromLatLngToPoint()和fromPointToLatLng():

This example contains a MercatorProjection object, which includes the methods fromLatLngToPoint() and fromPointToLatLng():

的http://$c$c.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html

一旦你转换你的(X,Y)至(纬度,经度),这是你如何画一个圆圈:

Once you have converted your (x,y) to (lat,lon), this is how you draw a circle:

// Pseudo code
var d = radius/6378800; // 6378800 is Earth radius in meters
var lat1 = (PI/180)* centerLat;
var lng1 = (PI/180)* centerLng;

// Go around a circle from 0 to 360 degrees, every 10 degrees
for (var a = 0 ; a < 361 ; a+=10 ) {
    var tc = (PI/180)*a;
    var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
    var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
    var x = ((lng1-dlng+PI) % (2*PI)) - PI ;
    var lat = y*(180/PI);
    var lon = x*(180/PI);

    // Convert the lat and lon to pixel (x,y) 
}

这两个混搭画一个给定半径的圆的地球表面上的:

These two mashups draw a circle of a given radius on the surface of the Earth:

http://maps.forum.nu/gm_sensitive_circle2.html

http://maps.forum.nu/gm_drag_polygon.html

如果您选择忽略投影,那么你会用直角坐标和简单地使用毕达哥拉斯定理画圆:

If you choose to ignore the projection then you'd use cartesian coordinates and simply draw the circle using Pythagoras Theorem:

http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates