Google Maps API کاشی های نقشه را در سطوح مختلف زوم برای تصاویر نوع نقشه فراهم می کند. بیشتر تصاویر نقشه راه، برای مثال، از سطوح زوم 0 تا 18 در دسترس هستند. تصاویر ماهواره ای بسیار متفاوت است زیرا این تصاویر تولید نمی شوند، بلکه مستقیماً عکس گرفته می شوند.
از آنجا که تصاویر ماهوارهای همیشه در سطوح زوم بالا برای مکانهای دوردست در دسترس نیستند - مناطق کم جمعیت یا مناطق باز اقیانوس - ممکن است بخواهید از قبل بالاترین سطح زوم را برای تصاویر در یک مکان مشخص بدانید. شی MaxZoomService یک رابط ساده برای کشف حداکثر سطح زوم در یک مکان معینی که Google Maps برای آن تصاویر ماهواره ای دارد، فراهم می کند.
درخواست های MaxZoom
دسترسی به MaxZoomService ناهمزمان است، زیرا Google Maps API باید با یک سرور خارجی تماس بگیرد. به همین دلیل، باید پس از تکمیل درخواست، یک متد برگشتی را ارسال کنید تا اجرا شود. این روش برگشتی باید نتیجه را پردازش کند.
برای شروع درخواست به MaxZoomService ، getMaxZoomAtLatLng() را فراخوانی کنید، LatLng مکان و تابع callback را ارسال کنید تا پس از تکمیل درخواست اجرا شود.
پاسخ های MaxZoom
هنگامی که getMaxZoomAtLatLng() تابع callback را اجرا می کند، دو پارامتر را پس می دهد:
status شامل MaxZoomStatus درخواست است.
zoom شامل سطح زوم است. اگر به دلایلی سرویس از کار بیفتد، این مقدار وجود نخواهد داشت.
کد status ممکن است یکی از مقادیر زیر را برگرداند:
OK نشان می دهد که این سرویس حداکثر سطح زوم را برای تصاویر ماهواره ای پیدا کرده است.
ERROR نشان می دهد که درخواست MaxZoom قابل پردازش نیست.
مثال زیر نقشه کلان شهر توکیو را نشان می دهد. کلیک کردن در هر نقطه از نقشه، حداکثر سطح زوم را در آن مکان نشان می دهد. (سطوح بزرگنمایی در اطراف توکیو به طور کلی بین سطوح زوم 18 و 21 متفاوت است.)
TypeScript
letmap:google.maps.Map;letmaxZoomService:google.maps.MaxZoomService;letinfoWindow:google.maps.InfoWindow;functioninitMap():void{map=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{zoom:11,center:{lat:35.6894,lng:139.692},mapTypeId:"hybrid",});infoWindow=newgoogle.maps.InfoWindow();maxZoomService=newgoogle.maps.MaxZoomService();map.addListener("click",showMaxZoom);}functionshowMaxZoom(e:google.maps.MapMouseEvent){maxZoomService.getMaxZoomAtLatLng(e.latLngasgoogle.maps.LatLng,(result:google.maps.MaxZoomResult)=>{if(result.status!=="OK"){infoWindow.setContent("Error in MaxZoomService");}else{infoWindow.setContent("The maximum zoom at this location is: "+result.zoom);}infoWindow.setPosition(e.latLng);infoWindow.open(map);});}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
letmap;letmaxZoomService;letinfoWindow;functioninitMap(){map=newgoogle.maps.Map(document.getElementById("map"),{zoom:11,center:{lat:35.6894,lng:139.692},mapTypeId:"hybrid",});infoWindow=newgoogle.maps.InfoWindow();maxZoomService=newgoogle.maps.MaxZoomService();map.addListener("click",showMaxZoom);}functionshowMaxZoom(e){maxZoomService.getMaxZoomAtLatLng(e.latLng,(result)=>{if(result.status!=="OK"){infoWindow.setContent("Error in MaxZoomService");}else{infoWindow.setContent("The maximum zoom at this location is: "+result.zoom,);}infoWindow.setPosition(e.latLng);infoWindow.open(map);});}window.initMap=initMap;
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe Google Maps \u003ccode\u003eMaxZoomService\u003c/code\u003e helps determine the highest zoom level available for satellite imagery at a specific location.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eMaxZoomService\u003c/code\u003e requests are asynchronous and require a callback function to handle the response, which includes a status and zoom level.\u003c/p\u003e\n"],["\u003cp\u003eThe response status can be \u003ccode\u003eOK\u003c/code\u003e indicating success or \u003ccode\u003eERROR\u003c/code\u003e if the request failed.\u003c/p\u003e\n"],["\u003cp\u003eA provided example demonstrates using the \u003ccode\u003eMaxZoomService\u003c/code\u003e to display the maximum zoom level when clicking on a map of Tokyo.\u003c/p\u003e\n"]]],["The `MaxZoomService` determines the highest zoom level for satellite imagery at a given location. It uses `getMaxZoomAtLatLng()` with a location's `LatLng` and a callback function. The callback returns a `status` (`OK` or `ERROR`) and the `zoom` level. Clicking on a map in the provided example triggers `getMaxZoomAtLatLng()`, which updates an info window with the maximum zoom level or an error message. Access to this service is asynchronous and requires a callback to process results.\n"],null,["1. [Maximum Zoom Imagery](#MaxZoom)\n2. [MaxZoom Requests](#MaxZoomRequests)\n3. [MaxZoom Responses](#MaxZoomResponses)\n\nOverview Also see the Maps JavaScript API Reference: [Max Zoom](/maps/documentation/javascript/reference/max-zoom)\n\nThe Google Maps API provides map tiles at various\n[zoom levels](/maps/documentation/javascript/tutorial#MapOptions) for map type imagery. Most roadmap\nimagery is available from zoom levels 0 to 18, for\nexample. Satellite imagery varies more widely as this\nimagery is not generated, but directly photographed.\n\nBecause satellite imagery is not always available at\nhigh zoom levels for remote locations --- sparsely populated\nareas or open ocean areas --- you may want to\nknow the highest zoom level for imagery at a given location\nbeforehand. The `MaxZoomService` object provides a\nsimple interface for discovering the maximum zoom level at a\ngiven location for which Google Maps has satellite imagery.\n\nMaxZoom Requests\n\nAccessing the `MaxZoomService` is asynchronous, since the\nGoogle Maps API needs to make a call to an external server. For\nthat reason, you need to pass a *callback* method to execute\nupon completion of the request. This callback method should process\nthe result.\n\nTo initiate a request to the `MaxZoomService`,\ncall `getMaxZoomAtLatLng()`, passing the\n`LatLng` of the location and a callback function\nto execute upon completion of the request.\n\nMaxZoom Responses\n\nWhen `getMaxZoomAtLatLng()` executes the *callback*\nfunction, it will pass back two parameters:\n\n- `status` contains the `MaxZoomStatus` of the request.\n- `zoom` contains the zoom level. If for some reason the service fails, this value will not be present.\n\nThe `status` code may return one of the following values:\n\n- `OK` indicates that the service found the maximum zoom level for satellite imagery.\n- `ERROR` indicates that the MaxZoom request could not be processed.\n\nThe following example shows a map of metropolitan Tokyo.\nClicking anywhere on the map indicates the maximum zoom level\nat that location. (Zoom levels around Tokyo generally vary\nbetween zoom levels 18 and 21.) \n\nTypeScript \n\n```typescript\nlet map: google.maps.Map;\nlet maxZoomService: google.maps.MaxZoomService;\nlet infoWindow: google.maps.InfoWindow;\n\nfunction initMap(): void {\n map = new google.maps.Map(document.getElementById(\"map\") as HTMLElement, {\n zoom: 11,\n center: { lat: 35.6894, lng: 139.692 },\n mapTypeId: \"hybrid\",\n });\n\n infoWindow = new google.maps.InfoWindow();\n\n maxZoomService = new google.maps.MaxZoomService();\n\n map.addListener(\"click\", showMaxZoom);\n}\n\nfunction showMaxZoom(e: google.maps.MapMouseEvent) {\n maxZoomService.getMaxZoomAtLatLng(\n e.latLng as google.maps.LatLng,\n (result: google.maps.MaxZoomResult) =\u003e {\n if (result.status !== \"OK\") {\n infoWindow.setContent(\"Error in MaxZoomService\");\n } else {\n infoWindow.setContent(\n \"The maximum zoom at this location is: \" + result.zoom\n );\n }\n\n infoWindow.setPosition(e.latLng);\n infoWindow.open(map);\n }\n );\n}\n\ndeclare global {\n interface Window {\n initMap: () =\u003e void;\n }\n}\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/samples/maxzoom-simple/index.ts#L8-L49\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nlet map;\nlet maxZoomService;\nlet infoWindow;\n\nfunction initMap() {\n map = new google.maps.Map(document.getElementById(\"map\"), {\n zoom: 11,\n center: { lat: 35.6894, lng: 139.692 },\n mapTypeId: \"hybrid\",\n });\n infoWindow = new google.maps.InfoWindow();\n maxZoomService = new google.maps.MaxZoomService();\n map.addListener(\"click\", showMaxZoom);\n}\n\nfunction showMaxZoom(e) {\n maxZoomService.getMaxZoomAtLatLng(e.latLng, (result) =\u003e {\n if (result.status !== \"OK\") {\n infoWindow.setContent(\"Error in MaxZoomService\");\n } else {\n infoWindow.setContent(\n \"The maximum zoom at this location is: \" + result.zoom,\n );\n }\n\n infoWindow.setPosition(e.latLng);\n infoWindow.open(map);\n });\n}\n\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/maxzoom-simple/docs/index.js#L7-L37\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n[View example](/maps/documentation/javascript/examples/maxzoom-simple)\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps/js-samples/tree/master/dist/samples/maxzoom-simple/jsfiddle) [Google Cloud Shell](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fgooglemaps%2Fjs-samples&cloudshell_git_branch=sample-maxzoom-simple&cloudshell_tutorial=cloud_shell_instructions.md&cloudshell_workspace=.)"]]