ui.Map.getCenter
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trả về toạ độ ở tâm bản đồ.
Cách sử dụng | Giá trị trả về |
---|
Map.getCenter() | Geometry.Point |
Đối số | Loại | Thông tin chi tiết |
---|
this: ui.map | ui.Map | Đối tượng ui.Map. |
Ví dụ
Trình soạn thảo mã (JavaScript)
// The default map in the Code Editor is a built-in ui.Map object called "Map".
// Let's refer to it as "defaultMap" for clarity.
var defaultMap = Map;
// ui.Map objects can be constructed. Here, a new map is declared.
var newMap = ui.Map({
center: {lat: 0, lon: 0, zoom: 1},
style: {position: 'bottom-right', width: '400px'}
});
// Add the newMap to the defaultMap.
defaultMap.add(newMap);
// You can set the viewport of a ui.Map to be centered on an object.
// Here, the defaultMap is centered on a point with a selected zoom level.
var geom = ee.Geometry.Point(-122.0841, 37.4223);
defaultMap.centerObject(geom, 18);
defaultMap.addLayer(geom, {color: 'orange'}, 'Googleplex');
// Map extent can be fetched using the ui.Map.getBounds method.
print('defaultMap bounds as a list',
defaultMap.getBounds());
print('defaultMap bounds as a dictionary',
ee.Dictionary.fromLists(['w', 's', 'e', 'n'], defaultMap.getBounds()));
print('defaultMap bounds as GeoJSON',
defaultMap.getBounds({asGeoJSON: true}));
// Map center point can be fetched using the ui.Map.getCenter method.
print('defaultMap center as a Point geometry', defaultMap.getCenter());
// Map zoom level can be fetched using the ui.Map.getZoom method.
print('defaultMap zoom level', defaultMap.getZoom());
// Map scale can be fetched using the ui.Map.getScale method.
print('defaultMap approximate pixel scale', defaultMap.getScale());
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eMap.getCenter()\u003c/code\u003e returns the coordinates of the center point of the map as a Geometry.Point object.\u003c/p\u003e\n"],["\u003cp\u003eThis method can be used with any ui.Map instance in Earth Engine Code Editor.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve the map's bounds, zoom level, and approximate pixel scale using other related methods like \u003ccode\u003egetBounds()\u003c/code\u003e, \u003ccode\u003egetZoom()\u003c/code\u003e, and \u003ccode\u003egetScale()\u003c/code\u003e, respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example demonstrates how to center the map on a specific point, add layers, and retrieve map properties.\u003c/p\u003e\n"]]],["The `Map.getCenter()` method retrieves the map's center coordinates as a `Geometry.Point`. It is used on a `ui.Map` instance. The provided examples demonstrate creating new maps, adding them to the default map, centering the map on a specific point, and fetching the map's bounds, center, zoom level, and scale. These operations are performed using the `getBounds`, `getCenter`, `getZoom`, and `getScale` methods on a map object.\n"],null,["# ui.Map.getCenter\n\n\u003cbr /\u003e\n\nReturns the coordinates at the center of the map.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------|----------------|\n| Map.getCenter`()` | Geometry.Point |\n\n| Argument | Type | Details |\n|----------------|--------|----------------------|\n| this: `ui.map` | ui.Map | The ui.Map instance. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// The default map in the Code Editor is a built-in ui.Map object called \"Map\".\n// Let's refer to it as \"defaultMap\" for clarity.\nvar defaultMap = Map;\n\n// ui.Map objects can be constructed. Here, a new map is declared.\nvar newMap = ui.Map({\n center: {lat: 0, lon: 0, zoom: 1},\n style: {position: 'bottom-right', width: '400px'}\n});\n\n// Add the newMap to the defaultMap.\ndefaultMap.add(newMap);\n\n// You can set the viewport of a ui.Map to be centered on an object.\n// Here, the defaultMap is centered on a point with a selected zoom level.\nvar geom = ee.Geometry.Point(-122.0841, 37.4223);\ndefaultMap.centerObject(geom, 18);\ndefaultMap.addLayer(geom, {color: 'orange'}, 'Googleplex');\n\n// Map extent can be fetched using the ui.Map.getBounds method.\nprint('defaultMap bounds as a list',\n defaultMap.getBounds());\nprint('defaultMap bounds as a dictionary',\n ee.Dictionary.fromLists(['w', 's', 'e', 'n'], defaultMap.getBounds()));\nprint('defaultMap bounds as GeoJSON',\n defaultMap.getBounds({asGeoJSON: true}));\n\n// Map center point can be fetched using the ui.Map.getCenter method.\nprint('defaultMap center as a Point geometry', defaultMap.getCenter());\n\n// Map zoom level can be fetched using the ui.Map.getZoom method.\nprint('defaultMap zoom level', defaultMap.getZoom());\n\n// Map scale can be fetched using the ui.Map.getScale method.\nprint('defaultMap approximate pixel scale', defaultMap.getScale());\n```"]]