Class Geocoder
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
โปรแกรมแปลงพิกัดภูมิศาสตร์
ช่วยให้แปลงที่อยู่เป็นพิกัดทางภูมิศาสตร์หรือแปลงพิกัดทางภูมิศาสตร์เป็นที่อยู่ได้
ตัวอย่างด้านล่างแสดงวิธีใช้คลาสนี้เพื่อค้นหาสถานที่ที่ตรงกันมากที่สุด 9 แห่งสำหรับ "Main St" ในโคโลราโด เพิ่มสถานที่เหล่านั้นลงในแผนที่ แล้วฝังลงใน Google เอกสารใหม่
// Find the best matches for "Main St" in Colorado.
const response = Maps.newGeocoder()
// The latitudes and longitudes of southwest and northeast
// corners of Colorado, respectively.
.setBounds(36.998166, -109.045486, 41.001666, -102.052002)
.geocode('Main St');
// Create a Google Doc and map.
const doc = DocumentApp.create('My Map');
const map = Maps.newStaticMap();
// Add each result to the map and doc.
for (let i = 0; i < response.results.length && i < 9; i++) {
const result = response.results[i];
map.setMarkerStyle(null, null, i + 1);
map.addMarker(result.geometry.location.lat, result.geometry.location.lng);
doc.appendListItem(result.formatted_address);
}
// Add the finished map to the doc.
doc.appendImage(Utilities.newBlob(map.getMapImage(), 'image/png'));
ดูเพิ่มเติม
เอกสารประกอบโดยละเอียด
geocode(address)
รับจุดทางภูมิศาสตร์โดยประมาณของที่อยู่หนึ่งๆ
// Gets the geographic coordinates for Times Square.
const response = Maps.newGeocoder().geocode('Times Square, New York, NY');
for (let i = 0; i < response.results.length; i++) {
const result = response.results[i];
Logger.log(
'%s: %s, %s',
result.formatted_address,
result.geometry.location.lat,
result.geometry.location.lng,
);
}
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
address | String | ที่อยู่ |
รีเทิร์น
Object
— ออบเจ็กต์ JSON ที่มีข้อมูลการแปลงพิกัดภูมิศาสตร์ตามที่อธิบายไว้ที่นี่
reverseGeocode(latitude, longitude)
รับที่อยู่โดยประมาณของจุดทางภูมิศาสตร์ที่ระบุ
// Gets the address of a point in Times Square.
const response = Maps.newGeocoder().reverseGeocode(40.758577, -73.984464);
for (let i = 0; i < response.results.length; i++) {
const result = response.results[i];
Logger.log(
'%s: %s, %s',
result.formatted_address,
result.geometry.location.lat,
result.geometry.location.lng,
);
}
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
latitude | Number | ละติจูดของจุด |
longitude | Number | ลองจิจูดของจุด |
รีเทิร์น
Object
— ออบเจ็กต์ JSON ที่มีข้อมูลการแปลงพิกัดภูมิศาสตร์ย้อนกลับตามที่อธิบายไว้ที่นี่
ดูเพิ่มเติม
setBounds(swLatitude, swLongitude, neLatitude, neLongitude)
กำหนดขอบเขตของพื้นที่ที่ควรได้รับการพิจารณาเป็นพิเศษในผลการค้นหา
// Creates a Geocoder that prefers points in the area of Manhattan.
const geocoder = Maps.newGeocoder().setBounds(
40.699642,
-74.021072,
40.877569,
-73.908548,
);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
swLatitude | Number | ละติจูดของมุมตะวันตกเฉียงใต้ของขอบเขต |
swLongitude | Number | ลองจิจูดของมุมตะวันตกเฉียงใต้ของขอบเขต |
neLatitude | Number | ละติจูดของมุมตะวันออกเฉียงเหนือของขอบเขต |
neLongitude | Number | ลองจิจูดของมุมตะวันออกเฉียงเหนือของขอบเขต |
รีเทิร์น
Geocoder
— ออบเจ็กต์ Geocoder เพื่อช่วยให้การเรียกใช้แบบต่อเนื่องง่ายขึ้น
ดูเพิ่มเติม
setLanguage(language)
ตั้งค่าภาษาที่จะใช้ในผลการค้นหา
// Creates a Geocoder with the language set to French.
const geocoder = Maps.newGeocoder().setLanguage('fr');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
language | String | ตัวระบุภาษา BCP-47 |
รีเทิร์น
Geocoder
— ออบเจ็กต์ Geocoder เพื่อช่วยให้การเรียกใช้แบบต่อเนื่องง่ายขึ้น
ดูเพิ่มเติม
setRegion(region)
ตั้งค่าภูมิภาคที่จะใช้เมื่อตีความชื่อสถานที่ รหัสภูมิภาคที่รองรับจะสอดคล้องกับ ccTLD ที่ Google Maps รองรับ เช่น รหัสภูมิภาค "uk" สอดคล้องกับ "maps.google.co.uk"
// Creates a Geocoder with the region set to France.
const geocoder = Maps.newGeocoder().setRegion('fr');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
region | String | รหัสภูมิภาคที่จะใช้ |
รีเทิร์น
Geocoder
— ออบเจ็กต์ Geocoder เพื่อช่วยให้การเรียกใช้แบบต่อเนื่องง่ายขึ้น
ดูเพิ่มเติม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eThe Geocoder class enables conversion between addresses and geographic coordinates (latitude and longitude).\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for finding geographic points for an address (geocode) and vice-versa (reverseGeocode).\u003c/p\u003e\n"],["\u003cp\u003eYou can specify bounds for preferred results, language, and region for location interpretation.\u003c/p\u003e\n"],["\u003cp\u003eGeocoder uses a JSON object to represent the geocoding and reverse geocoding data.\u003c/p\u003e\n"],["\u003cp\u003eIt leverages the Google Geocoding API for its functionality and supports various region codes.\u003c/p\u003e\n"]]],[],null,["# Class Geocoder\n\nGeocoder\n\nAllows for the conversion between an address and geographical coordinates. \n\nThe example below shows how you can use this class find the top nine matches for the location\n\"Main St\" in Colorado, add them to a map, and then embed it in a new Google Doc.\n\n```javascript\n// Find the best matches for \"Main St\" in Colorado.\nconst response = Maps.newGeocoder()\n // The latitudes and longitudes of southwest and northeast\n // corners of Colorado, respectively.\n .setBounds(36.998166, -109.045486, 41.001666, -102.052002)\n .geocode('Main St');\n\n// Create a Google Doc and map.\nconst doc = DocumentApp.create('My Map');\nconst map = Maps.newStaticMap();\n\n// Add each result to the map and doc.\nfor (let i = 0; i \u003c response.results.length && i \u003c 9; i++) {\n const result = response.results[i];\n map.setMarkerStyle(null, null, i + 1);\n map.addMarker(result.geometry.location.lat, result.geometry.location.lng);\n doc.appendListItem(result.formatted_address);\n}\n\n// Add the finished map to the doc.\ndoc.appendImage(Utilities.newBlob(map.getMapImage(), 'image/png'));\n```\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding) \n\n### Methods\n\n| Method | Return type | Brief description |\n|--------------------------------------------------------------------------------------------------------|---------------|----------------------------------------------------------------------------------|\n| [geocode(address)](#geocode(String)) | `Object` | Gets the approximate geographic points for a given address. |\n| [reverseGeocode(latitude, longitude)](#reverseGeocode(Number,Number)) | `Object` | Gets the approximate addresses for a given geographic point. |\n| [setBounds(swLatitude, swLongitude, neLatitude, neLongitude)](#setBounds(Number,Number,Number,Number)) | [Geocoder](#) | Sets the bounds of an area that should be given extra preference in the results. |\n| [setLanguage(language)](#setLanguage(String)) | [Geocoder](#) | Sets the language to be used in the results. |\n| [setRegion(region)](#setRegion(String)) | [Geocoder](#) | Sets a region to use when interpreting location names. |\n\nDetailed documentation\n----------------------\n\n### `geocode(address)`\n\nGets the approximate geographic points for a given address.\n\n```javascript\n// Gets the geographic coordinates for Times Square.\nconst response = Maps.newGeocoder().geocode('Times Square, New York, NY');\nfor (let i = 0; i \u003c response.results.length; i++) {\n const result = response.results[i];\n Logger.log(\n '%s: %s, %s',\n result.formatted_address,\n result.geometry.location.lat,\n result.geometry.location.lng,\n );\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|-------------|\n| `address` | `String` | an address |\n\n#### Return\n\n\n`Object` --- a JSON Object containing the geocoding data, as described [here](/maps/documentation/geocoding#JSON)\n\n*** ** * ** ***\n\n### `reverse``Geocode(latitude, longitude)`\n\nGets the approximate addresses for a given geographic point.\n\n```javascript\n// Gets the address of a point in Times Square.\nconst response = Maps.newGeocoder().reverseGeocode(40.758577, -73.984464);\nfor (let i = 0; i \u003c response.results.length; i++) {\n const result = response.results[i];\n Logger.log(\n '%s: %s, %s',\n result.formatted_address,\n result.geometry.location.lat,\n result.geometry.location.lng,\n );\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|----------|----------------------------|\n| `latitude` | `Number` | the latitude of the point |\n| `longitude` | `Number` | the longitude of the point |\n\n#### Return\n\n\n`Object` --- a JSON Object containing the reverse geocoding data, as described [here](/maps/documentation/geocoding#ReverseGeocoding)\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding#JSON)\n\n*** ** * ** ***\n\n### `set``Bounds(swLatitude, swLongitude, neLatitude, neLongitude)`\n\nSets the bounds of an area that should be given extra preference in the results.\n\n```javascript\n// Creates a Geocoder that prefers points in the area of Manhattan.\nconst geocoder = Maps.newGeocoder().setBounds(\n 40.699642,\n -74.021072,\n 40.877569,\n -73.908548,\n);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|----------|------------------------------------------------------|\n| `sw``Latitude` | `Number` | the latitude of the south west corner of the bounds |\n| `sw``Longitude` | `Number` | the longitude of the south west corner of the bounds |\n| `ne``Latitude` | `Number` | the latitude of the north east corner of the bounds |\n| `ne``Longitude` | `Number` | the longitude of the north east corner of the bounds |\n\n#### Return\n\n\n[Geocoder](#) --- the Geocoder object to facilitate chaining of calls\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding#Viewports)\n\n*** ** * ** ***\n\n### `set``Language(language)`\n\nSets the language to be used in the results.\n\n```javascript\n// Creates a Geocoder with the language set to French.\nconst geocoder = Maps.newGeocoder().setLanguage('fr');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|------------------------------|\n| `language` | `String` | a BCP-47 language identifier |\n\n#### Return\n\n\n[Geocoder](#) --- the Geocoder object to facilitate chaining of calls.\n\n#### See also\n\n- [Encoded Polyline Format](/maps/documentation/utilities/polylinealgorithm)\n\n*** ** * ** ***\n\n### `set``Region(region)`\n\nSets a region to use when interpreting location names. The supported region codes correspond to\nthe ccTLDs supported by Google Maps. For example, the region code \"uk\" corresponds to\n\"maps.google.co.uk\".\n\n```javascript\n// Creates a Geocoder with the region set to France.\nconst geocoder = Maps.newGeocoder().setRegion('fr');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|----------|------------------------|\n| `region` | `String` | the region code to use |\n\n#### Return\n\n\n[Geocoder](#) --- the Geocoder object to facilitate chaining of calls\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding#RegionCodes)"]]