使用数学(mercator)覆盖静态谷歌地图上的lat / lng gps坐标

时间:2013-03-10 14:28:14

标签: google-maps maps geospatial mercator

(不使用投影库) 我知道我的地图的中心点,(-37.500,175.500).zoom(13)大小。 400x400px,这是一个墨卡托投影(标准谷歌地图)。 它用作画布400x400px上的背景图像。 我如何计算出这张地图的边界。

1 个答案:

答案 0 :(得分:0)

假设您使用中心坐标来订购地图,
    缩放= 13 //谷歌地图缩放级别(1-18etc)
    screenwidth = 400(像素)//地图的宽度
    Latctr = -37.450 //地图中间的纬度
    Longctr = 170.250 //地图中间的经度
    1 / Lengthlat = 111111 // 1度纬度的米长度
    2 / Lengthlong = cos长度* 111111 //经度1度的长度
    3 / Ratiolengths == lengthlat / lengthlong
    4 / LongitudeValueAdjust =((lengthlat /(2 ^ zoom)/(screenwidth * 2)* RatioLengths
    5 / LatitudeValueAdjust =(lengthlat /(2 ^ zoom)/(screenwidth * 2)
    6 / Northwestlat = latctr + latitudeValueAdjust
    7 / Northwestlong = longctr -longValueAdjust
    8 / Southeastlat = latctr - LatValueAdjust
    9 / Southeastlong = longctr + longValueAdjust
    现在您知道了地图角落的坐标

Plotting lat lng to canvas/screen x,y  
//This is not a mercator projection, works fine for zooms > 9
Assumes 0,0 is the top left hand corner of the canvas  
lattodraw // Latitude value of the coordinate we wish to convert  
longtodraw // Longitude value of the coordinate we wish to convert  
1/Latplot = canavsheight /(southeastlat-northwestlat) * lattodraw-northwestlat  
2/Longplot = canvaswidth /(southeastlong-northwestlong) * longtodraw-northwestlong  
3/Draw pixel at latplot,longplot