地图和图块坐标
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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,地图上的每个 x
和 y
像素可使用 0 到 256 * 219 之间的值来定位。
世界坐标建立在地图的图块大小基础之上,因此,像素坐标整数部分的作用是标识该位置在当前缩放级别下的确切像素。请注意,对于缩放级别 0,像素坐标等于世界坐标。
现在,我们可以在每个缩放级别精确表示地图上的每个位置。Maps SDK for Android 会根据指定的地图中心点(采用 LatLng
形式)缩放级别和外围 DOM 元素的大小来构造视口,并将此边界框转换为像素坐标。然后,API 从逻辑上确定位于指定像素边界内的所有地图图块。每个地图图块均使用图块坐标来定位,这大大简化了地图图像的显示。
图块坐标
对于较高的缩放级别,API 无法一次加载所有地图图像。相反,API 将各缩放级别的图像分解成一组在逻辑上以便于应用理解的顺序排列的地图图块。当地图滚动至新位置,或者切换到新的缩放级别时,API 会使用像素坐标确定需要哪些图块,然后将这些值转换为需要检索的一组图块。这些图块坐标采用特殊的分配架构,使得在逻辑上更容易确定哪个图块包含指定位置点的图像。
Google 地图中的图块从与像素原点相同的位置开始编号。为了便于 Google 实现墨卡托投影法,原点图块始终位于地图的西北角,x
值从西向东增加,y
值从北向南增加。系统使用基于该原点的 x,y
坐标为图块建立索引。例如,缩放级别为 2 时,地球分成 16 个图块,每个图块都可通过唯一的 x,y
来定位。

请注意,通过将像素坐标除以图块大小 (256) 并取结果的整数部分,可以生成当前缩放级别的图块坐标。
示例
下例显示了伊利诺州芝加哥市的坐标:纬度/经度值、世界坐标、像素坐标以及图块坐标。使用缩放控件可查看不同缩放级别的坐标值。
如需了解这些坐标的计算方式,请查看此处的代码。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-06-28。
[null,null,["最后更新时间 (UTC):2024-06-28。"],[[["\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)."]]