Jon*_*han 7 .net maps google-maps pixel coordinates
我正在尝试在ASP.NET中开发一个页面,它将充当Google Map的tile-server
它将从数据库中提取一组纬度/经度点,然后在给定缩放级别(默认值:15)的情况下将它们渲染为透明背景上的小红点.
然后它将结果作为GIF类型的图像返回.
是否开发了任何算法或库,允许我采用这组纬度/经度并将其转换为一组2D像素坐标,给定缩放级别?
(这一切都是在服务器端完成的,因此我无法使用Google Maps API.)
更新:在Perl中找到了类似的代码示例:
http://blog.barros.ws/2009/03/06/convert-lat-lng-and-zoom-values-to-pixel-xy-on-a-map/
麻烦的是,我不知道Perl,也没有时间破解书籍并学习它.
任何人都可以帮我解读这个函数中发生的事情吗?
sub Google_Coord_to_Pix
{
my $value = shift ;
my $lat = shift ;
my $lng = shift ;
my @d = ( ) ;
my $e = 0 ;
$d[1] = sprintf("%0.0f", $$value{'bmO'} + $lng * $$value{'pixLngDeg'} ) ;
$e = sin($lat * $$value{'Wa'}) ;
if( $e > 0.99999 )
{
$e = 0.99999 ;
}
if( $e < -0.99999 )
{
$e = -0.99999 ;
}
$d[0] = sprintf("%0.0f", $$value{'bmO'} + 0.5 * log((1 + $e) / (1 - $e)) * (-1) * $$value{'pixLngRad'} ) ;
return (@d) ;
}
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的一些代码.它是在PHP中.
// Returns longitude in pixels at a certain zoom level
function lonToX($lon, $zoom) {
$offset = 256 << ($zoom-1);
return round($offset + ($offset * $lon / 180));
}
// Returns latitude in pixels at a certain zoom level
function latToY($lat, $zoom) {
$offset = 256 << ($zoom-1);
return round($offset - $offset/pi() * log((1 + sin($lat * pi() / 180)) / (1 - sin($lat * pi() / 180))) / 2);
}
Run Code Online (Sandbox Code Playgroud)
祝好运!
更新: 此地图是帮助了解图块在Google地图中的工作方式的绝佳方式
编辑:这是VB.NET中的一组等效函数:
Public Function LonToX(Lon As Double, Zoom as UInteger) As UInteger
Dim Offset = 256 << (Zoom - 1)
Return Math.Round(Offset + (Offset * Lon / 180))
End Function
Public Function LatToY(Lat As Double, Zoom as UInteger) As UInteger
Dim Offset = 256 << (Zoom - 1)
Return Math.Round(Offset - Offset / Math.Pi * Math.Log((1 + Math.Sin(Lat * Math.Pi / 180)) / (1 - Math.Sin(Lat * Math.Pi / 180))) / 2)
End Function
Run Code Online (Sandbox Code Playgroud)
在C#中:
public uint lonToX(double lon, uint zoom) {
uint offset = 256 << (zoom - 1);
return Math.Round(offset + (offset * lon / 180));
}
public uint latToY(double lat, uint zoom) {
uint offset = 256 << (zoom - 1);
return Math.Round(offset - offset / Math.Pi * Math.Log((1 + Math.Sin(lat * Math.Pi / 180)) / (1 - Math.Sin(lat * Math.Pi / 180))) / 2);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11661 次 |
| 最近记录: |