到底不使用Google Map API,自己強行將marker將到Map上有多麻煩嗎?
以下是已知的︰
1) Map中心的經緯度(LAT & LNG),以及Map圖片中心的(x, y)
2) 某point的經緯度(lat & lng)
3) Map的zoom level (Z)
求某point a的(xa, ya)
latest #7
首先先要得出268435456這數值,這是在zoom level最大值21的時候,整個地球圓周的一半轉化成pixel的值
然後就是...
offset = 268435456;
radius = offset / PI;
// zoom level = 21下的pixel值...
centerPixelX = round(offset + radius * LNG * PI / 180);
pointPixelX = round(offset + radius * lng * PI / 180);
diffX = (pointPixelX - centerPixelX) / 2^(21-Z);
diffX就是某point與Map中心的pixel差,然後是Y...
centerPixelY = round(offset - radius * log( (1+sin(LATPI/180)) / (1-sin(LATPI/180)) ) / 2);
pointPixelY = round(offset - radius * log( (1+sin(latPI/180)) / (1-sin(latPI/180)) ) / 2);
diffY = (pointPixelY - centerPixelY) / 2^(21-Z);
YEAH!!!!!!!!!!!!!!! 就是這麼簡單.............
然後我發現我還要再寫一個reverse function....................
reverse X還好,reverse Y好像是魔王級別的...
back to top