Google Maps Tile-related operations (Js,google maps v3)

Source: Internet
Author: User
Tags pow

Some time ago, due to work reasons, the study of Google Maps tile-related operations. Know the latitude and longitude of a point and the map level, get the URL of the tile where the point resides; the URL of a tile is known, the upper-left corner of the tile is computed, the latitude and longitude of the tiles are known, and the pixel values on the world map are computed for a point latitude and longitude and map level.

1, know the latitude and longitude of a point and map level, get the URL of the tile where the point resides

Reference to two blog: this blog (http://blog.csdn.net/lijun_xiao2009/article/details/8178578) in the principle, but the use of the formula is too difficult to forget, combined with another blog (http:// BLOG.CSDN.NET/ZHAOBMOX/ARTICLE/DETAILS/1253005) inside the operation.

Manage Tile path function Calculationurl (val_lat,val_lng) {val_lng = parsefloat (VAL_LNG); Val_lat = parsefloat (Val_lat); var val_zoom = mapattr.cutzoom;//map level, set to global variable var zoomn = Math.pow (2,val_zoom); var x = Calc ULATIONLNG (VAL_LNG); var y = Calculationlat (Val_lat);//urldivvar url_x = X*zoomn;var url_y = Y*zoomn;return [Math.floor ( url_x), Math.floor (url_y)];} Calculate tile x-value function calculationlng (LNG) {var x = (180.0 + parsefloat (LNG))/360.0;return x according to longitude;}  Calculates the tile y-value function Calculationlat (LAT) {var PI = Math.pi;//3.1415926535897;var y =-parsefloat (lat) * pi/180; y = 0.5 * per latitude Math.log ((1+math.sin (Y))/(1-math.sin (y))); Y *= 1.0/(2 * PI); Y + = 0.5;return y;}

The resulting data is spelled ".../' +zoom+ '/' +x+ '/' +y+ '. png '", zoom is the map level and XY is the data just calculated.

2, the URL of a tile is known, calculate the top left corner of the tile latitude and longitude

Reference the blog: http://www.cnblogs.com/Tangf/archive/2012/04/07/2435545.html

function calculationlatlng (x, y) {var PI = Math.pi;var Zoomn = Math.pow (2,mapattr.cutzoom);//map level, set as global variable var LNG = X/zoomn *360.0-180.0;var a = pi* (1-2*y/zoomn), var e = Math.e;var rad = (Math.pow (e,a)-math.pow (e,-a)) *0.5var Latrad = Math.atan (ra D) var lat = latrad*180.0/pi;return {"lat": Lat, "LNG": LNG};}

3, known a point latitude and longitude and map level, calculate this point on the world map of the pixel value

Refer to the Baidu Library: http://wenku.baidu.com/link?url= Lg31km26tjhtytmbkwmq92lneu7p-aukeowfrej62rbsgrc7sive9vk2rq64sk0dlmvfs1zeidmx44sklxvzyct_njw2guhjqyxksxbvmak

Calculates the pixel value of a point on the world map function calculationpixeldistance (lat,lng) {var zoom = Mapattr.cutzoom;<span style= "font-family : Arial, Helvetica, Sans-serif; >//map level, set to global variable </span>//the coordinates of the first tile of the world map with the pixel var X = lngtopixel_x (lng,zoom); var Y = lattopixel_y (lat,zoom); return {X:math.floor (x), Y:math.floor (Y)};} Calculates x-pixel values by longitude function lngtopixel_x (lng,zoom) {return (lng+180) * (256<<zoom)/360;} Calculates y-pixel values according to Latitude function lattopixel_y (lat,zoom) {var siny = Math.sin (lat*math.pi/180); var y = Math.log ((1+siny)/(1-siny)) Return (128<<zoom) * (1-y/(2*MATH.PI));}


Google Maps Tile-related operations (Js,google maps v3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.