Class Geocoder

พิกัดภูมิศาสตร์

ทำให้สามารถแปลงระหว่างที่อยู่และพิกัดทางภูมิศาสตร์ได้
ตัวอย่างด้านล่างแสดงวิธีใช้ชั้นเรียนนี้เพื่อหาสถานที่ที่ตรงกัน 9 อันดับแรกในตำแหน่ง "ถนนบรมราชชนนี" ในโคโลราโด แล้วเพิ่มลงในแผนที่ แล้วฝังลงใน Google เอกสารฉบับใหม่

// Find the best matches for "Main St" in Colorado.
var 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.
var doc = DocumentApp.create('My Map');
var map = Maps.newStaticMap();

// Add each result to the map and doc.
for (var i = 0; i < response.results.length && i < 9; i++) {
  var 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)Objectรับจุดทางภูมิศาสตร์โดยประมาณสำหรับที่อยู่ที่ระบุ
reverseGeocode(latitude, longitude)Objectรับที่อยู่โดยประมาณสำหรับจุดทางภูมิศาสตร์ที่กำหนด
setBounds(swLatitude, swLongitude, neLatitude, neLongitude)Geocoderกำหนดขอบเขตของพื้นที่ที่ควรให้ความสำคัญเป็นพิเศษในผลลัพธ์
setLanguage(language)Geocoderตั้งค่าภาษาที่ใช้ในผลการค้นหา
setRegion(region)Geocoderตั้งค่าภูมิภาคที่จะใช้เมื่อแปลความหมายชื่อสถานที่

เอกสารประกอบโดยละเอียด

geocode(address)

รับจุดทางภูมิศาสตร์โดยประมาณสำหรับที่อยู่ที่ระบุ

// Gets the geographic coordinates for Times Square.
var response = Maps.newGeocoder().geocode('Times Square, New York, NY');
for (var i = 0; i < response.results.length; i++) {
  var result = response.results[i];
  Logger.log('%s: %s, %s', result.formatted_address, result.geometry.location.lat,
      result.geometry.location.lng);
}

พารามิเตอร์

ชื่อTypeคำอธิบาย
addressStringที่อยู่

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลการระบุพิกัดทางภูมิศาสตร์ตามที่อธิบายไว้ที่นี่


reverseGeocode(latitude, longitude)

รับที่อยู่โดยประมาณสำหรับจุดทางภูมิศาสตร์ที่กำหนด

// Gets the address of a point in Times Square.
var response = Maps.newGeocoder().reverseGeocode(40.758577, -73.984464);
for (var i = 0; i < response.results.length; i++) {
  var result = response.results[i];
  Logger.log('%s: %s, %s', result.formatted_address, result.geometry.location.lat,
      result.geometry.location.lng);
}

พารามิเตอร์

ชื่อTypeคำอธิบาย
latitudeNumberละติจูดของจุด
longitudeNumberลองจิจูดของจุด

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลการเข้ารหัสภูมิศาสตร์แบบย้อนกลับ ตามที่อธิบายไว้ที่นี่

ดูเพิ่มเติม


setBounds(swLatitude, swLongitude, neLatitude, neLongitude)

กำหนดขอบเขตของพื้นที่ที่ควรให้ความสำคัญเป็นพิเศษในผลลัพธ์

// Creates a Geocoder that prefers points in the area of Manhattan.
var geocoder = Maps.newGeocoder()
    .setBounds(40.699642, -74.021072, 40.877569, -73.908548);

พารามิเตอร์

ชื่อTypeคำอธิบาย
swLatitudeNumberละติจูดของมุมตะวันตกเฉียงใต้ของขอบเขต
swLongitudeNumberลองจิจูดของมุมตะวันตกเฉียงใต้ของขอบเขต
neLatitudeNumberละติจูดของมุมตะวันออกเฉียงเหนือของเขตแดน
neLongitudeNumberลองจิจูดของมุมตะวันออกเฉียงเหนือของขอบเขต

รีเทิร์น

Geocoder — ออบเจ็กต์ Geocoder เพื่ออำนวยความสะดวกในห่วงโซ่การเรียก

ดูเพิ่มเติม


setLanguage(language)

ตั้งค่าภาษาที่ใช้ในผลการค้นหา

// Creates a Geocoder with the language set to French.
var geocoder = Maps.newGeocoder().setLanguage('fr');

พารามิเตอร์

ชื่อTypeคำอธิบาย
languageStringตัวระบุภาษา BCP-47

รีเทิร์น

Geocoder — ออบเจ็กต์ Geocoder เพื่ออำนวยความสะดวกในห่วงโซ่การเรียก

ดูเพิ่มเติม


setRegion(region)

ตั้งค่าภูมิภาคที่จะใช้เมื่อแปลความหมายชื่อสถานที่ รหัสภูมิภาคที่รองรับจะสอดคล้องกับ ccTLD ที่ Google Maps รองรับ ตัวอย่างเช่น รหัสภูมิภาค "uk" สอดคล้องกับ "maps.google.co.uk"

// Creates a Geocoder with the region set to France.
var geocoder = Maps.newGeocoder().setRegion('fr');

พารามิเตอร์

ชื่อTypeคำอธิบาย
regionStringรหัสภูมิภาคที่จะใช้

รีเทิร์น

Geocoder — ออบเจ็กต์ Geocoder เพื่ออำนวยความสะดวกในห่วงโซ่การเรียก

ดูเพิ่มเติม