地圖與圖塊座標
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Maps SDK for Android 使用下列座標系統:
- 經緯度值,對應世界上某一點的專屬位置 (Google 使用世界大地測量系統 WGS84 標準)。
- 世界座標,對應地圖上某一點的專屬位置。
- 像素座標,對應特定縮放等級下地圖上的特定像素。
- 圖塊座標,對應特定縮放等級下地圖上的特定圖塊。
世界座標
每次 API 需要將世界上的某個地點轉譯成地圖上的某個位置時,會先將緯度值和經度值轉譯為「世界」座標。API 會使用麥卡托投影執行這項轉譯。
為方便計算像素座標 (如下方所示),我們假設縮放等級為 0 的地圖是採用基本圖塊大小的單一圖塊。接著,我們依照縮放等級為 0 的像素座標定義世界座標,使用投影法將經緯度轉換成基本圖塊上的像素位置。此世界座標是從地圖投影的原點測量至特定位置的浮點值。請注意,由於這個座標是浮點值,相較於目前顯示的地圖解析度,這個浮點值的精確度可能會高很多。也就是說,世界座標與目前的縮放等級無關。
Google 地圖中的世界座標是從麥卡托投影的原點 (地圖的西北角,經度 180 度,緯度約 85 度) 開始測量;向東 (右) 增加 x
向度,向南 (下) 增加 y
向度。基本的麥卡托 Google 地圖圖塊是 256 x 256 像素,因此可用的世界座標空間是 {0-256}, {0-256}
。

請注意,麥卡托投影的經度寬度有限制,但緯度高度沒有限制。我們利用麥卡托投影在大約 +/- 85 度的位置裁切基本地圖圖像,讓最終地圖呈正方形,以簡化選取圖塊的方式。請注意,在某些情況下 (例如您繪製的地點非常接近極點時),投影可能會產生落在基本地圖可用座標空間以外的世界座標。
像素座標
「像素座標」對應特定縮放等級下地圖上的特定像素;世界座標則會反映特定投影的絕對位置。像素座標是利用下列公式計算而得:
pixelCoordinate = worldCoordinate * 2zoomLevel
在上述公式中,請留意每增加一個縮放等級,x
和 y
向度都會變成原來的兩倍。因此,每增加一個縮放等級,其解析度就會是前一個等級的四倍。例如,縮放等級為 1 時,地圖包含 4 個 256x256 像素圖塊,因此像素空間為 512x512。縮放等級為 19 時,可使用 0 到 256 * 219 之間的值,對應到地圖上的每一個 x
和 y
像素。
世界座標是以地圖的圖塊大小為基準,因此我們可以利用像素座標的整數部分,找出在目前縮放等級下該位置的確切像素。請注意,縮放等級為 0 時,像素座標與世界座標相等。
現在,我們可以在每個縮放等級下,精確表示地圖上的各個位置。Maps SDK for Android 會根據縮放等級、地圖中心 (以 LatLng
的形式表示) 和內含 DOM 元素的尺寸,建立一個可視區域,並將這個定界框轉譯為像素座標。接下來,API 就可以按照邏輯判斷落在指定像素範圍內的所有地圖圖塊。每個地圖圖塊都可用圖塊座標參照,因此能大幅簡化地圖圖像的顯示作業。
圖塊座標
API 無法在較高的縮放等級下,一次載入所有地圖圖像,而是會將各個縮放等級的圖像,分解成一組依照應用程式理解的邏輯順序排列的地圖圖塊。地圖捲動到新位置或調至新的縮放等級時,API 會使用像素座標來判斷需要哪些圖塊,然後將這些值轉譯成要擷取的一組圖塊。系統會利用一套可依照邏輯輕易判斷的配置指定這些圖塊座標;透過這套配置,即可得知哪些圖塊包含任意特定點的圖像。
Google 地圖中的圖塊是從與像素原點相同的位置開始編號。在 Google 的麥卡托投影實作中,原點圖塊一律位於地圖的西北角,同時 x
值會從西到東遞增,y
值則從北到南遞增。圖塊是使用從該原點開始的 x,y
座標來建立索引。舉例來說,縮放等級為 2 時,如果將地球區分成 16 個圖塊,每個圖塊都可使用不重複的 x,y
組合參照:

請注意,只要將像素座標除以圖塊大小 (256) 並取計算結果的整數部分,即可得到目前縮放等級附帶產生的圖塊座標。
範例
下方範例顯示伊利諾州芝加哥市的各類座標:緯度值/經度值、世界座標、像素座標和圖塊座標。使用縮放控制項即可查看各個縮放等級的座標值。
如要瞭解座標的計算方式,請查看程式碼。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-07-01 (世界標準時間)。
[null,null,["上次更新時間:2024-07-01 (世界標準時間)。"],[[["\u003cp\u003eThe Maps SDK for Android uses four coordinate systems: latitude/longitude, world, pixel, and tile coordinates.\u003c/p\u003e\n"],["\u003cp\u003eWorld coordinates are based on the Mercator projection and represent locations independent of zoom level.\u003c/p\u003e\n"],["\u003cp\u003ePixel coordinates denote a specific pixel on the map at a given zoom level, calculated using world coordinates and zoom level.\u003c/p\u003e\n"],["\u003cp\u003eTile coordinates simplify map imagery display by dividing the map into a grid of tiles, referenced by x,y coordinates.\u003c/p\u003e\n"],["\u003cp\u003eTile coordinates are derived from pixel coordinates and zoom level, facilitating efficient loading of map imagery.\u003c/p\u003e\n"]]],["The Maps SDK uses four coordinate systems: latitude/longitude (WGS84 standard), world, pixel, and tile. World coordinates, derived via Mercator projection, represent locations on the map relative to a base tile at zoom level 0. Pixel coordinates, calculated as `worldCoordinate * 2^zoomLevel`, specify pixels at specific zoom levels. Tile coordinates, determined by dividing pixel coordinates by tile size (256), reference specific map tiles for loading imagery. Each coordinate type is essential for rendering and managing map data.\n"],null,["# Map and Tile Coordinates\n\nSelect platform: [Android](/maps/documentation/android-sdk/coordinates \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/coordinates \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/coordinates \"View this page for the JavaScript platform docs.\")\n\nThe Maps SDK for Android uses the following coordinate systems:\n\n- Latitude and longitude values, which reference a point on the world uniquely. (Google uses the [World Geodetic\n System WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System) standard.)\n- World coordinates, which reference a point on the map uniquely.\n- Pixel coordinates, which reference a specific pixel on the map at a specific zoom level.\n- Tile coordinates, which reference a specific tile on the map at a specific zoom level.\n\nWorld coordinates\n-----------------\n\nWhenever the API needs to translate a location in the world to a location on\na map, it first translates latitude and longitude values into a\n*world* coordinate. The API uses the\n[Mercator\nprojection](https://en.wikipedia.org/wiki/Mercator_projection) to perform this translation.\n\nFor convenience in the calculation of pixel coordinates (see below)\nwe assume a map at zoom level 0 is a single tile of the base tile size.\nWe then define world coordinates relative to pixel coordinates at zoom\nlevel 0, using the projection to convert latitudes and longitudes to\npixel positions on this base tile. This world coordinate is a floating\npoint value measured from the origin of the map projection to the\nspecific location. Note that since this value is a floating point value,\nit may be much more precise than the current resolution of the map image\nbeing shown. A world coordinate is independent of the current zoom level,\nin other words.\n\nWorld coordinates in Google Maps are measured from the Mercator\nprojection's origin (the northwest corner of the map at 180 degrees\nlongitude and approximately 85 degrees latitude) and increase in\nthe `x` direction towards the east (right) and increase in\nthe `y` direction towards the south (down). Because the\nbasic Mercator Google Maps tile is 256 x 256 pixels, the usable\nworld coordinate space is `{0-256}, {0-256}`.\n\nNote that a Mercator projection has a finite\nwidth longitudinally but an infinite height latitudinally. We cut off\nbase map imagery utilizing the Mercator projection at approximately\n+/- 85 degrees to make the resulting map shape square, which allows\neasier logic for tile selection. Note that a projection may produce\nworld coordinates outside the base map's usable coordinate space\nif you plot very near the poles, for example.\n\nPixel coordinates\n-----------------\n\n*Pixel coordinates* reference a specific pixel on the map at a\nspecific zoom level, whereas world coordinates reflect absolute locations on a\ngiven projection. Pixel coordinates are calculated using the following\nformula: \n\n```scdoc\npixelCoordinate = worldCoordinate * 2zoomLevel\n```\n\nFrom the above equation, note that each increasing zoom level\nis twice as large in both the `x` and `y`\ndirections. Therefore, each higher zoom level results in a resolution four\ntimes higher than the preceding level. For example, at zoom level 1,\nthe map consists of 4 256x256 pixels tiles, resulting in a pixel space\nfrom 512x512. At zoom level 19, each `x` and `y` pixel\non the map can be referenced using a value between\n0 and 256 \\* 2^19^.\n\nBecause we based world coordinates on the map's tile size, a\npixel coordinate's integer part has the effect of identifying the exact pixel\nat that location in the current zoom level. Note that for zoom level 0, the\npixel coordinates are equal to the world coordinates.\n\nWe now have a way to accurately denote each location on the map,\nat each zoom level. The Maps SDK for Android constructs a viewport\ngiven the zoom level center of the map (as a `LatLng`) and the\nsize of the containing DOM element, and\ntranslates this bounding box into pixel coordinates. The API then determines\nlogically all map tiles which lie within the given pixel bounds. Each of\nthese map tiles are referenced using [tile coordinates](#tile-coordinates) which greatly simplify the displaying of map\nimagery.\n\nTile coordinates\n----------------\n\nThe API cannot load all the map imagery at once for the higher zoom levels.\nInstead, the API breaks up the imagery at each zoom level\ninto a set of map tiles, which are logically arranged in an order which the\napplication understands. When a map scrolls to a new location, or to a new\nzoom level, the API determines which tiles are needed\nusing pixel coordinates, and translates those values into a set\nof tiles to retrieve. These tile coordinates are assigned using\na scheme which makes it logically easy to determine which tile contains\nthe imagery for any given point.\n\nTiles in Google Maps are numbered from the same origin as that\nfor pixels. For Google's implementation of the Mercator projection, the\norigin tile is always at the northwest corner\nof the map, with `x` values increasing from west to\neast and `y` values increasing from north to south. Tiles\nare indexed using `x,y` coordinates from that origin. For\nexample, at zoom level 2, when the earth is divided up into 16 tiles,\neach tile can be referenced by a unique `x,y` pair:\n\nNote that by dividing the pixel coordinates by the tile size (256) and\ntaking the integer parts of the result, you produce as a by-product\nthe tile coordinate at the current zoom level.\n\nExample\n-------\n\nThe following example displays coordinates for Chicago, IL:\nlatitude/longitude values, world coordinates, pixel coordinates, and tile\ncoordinates. Use the zoom control to see the coordinate values at various\nzoom levels.\n\nTo see how the coordinates were calculated,\n[view\nthe code](/maps/documentation/javascript/examples/map-coordinates)."]]