Class Geocoder

Geocoder

تتيح هذه الخدمة التحويل بين عنوان وإحداثيات جغرافية.
يوضّح المثال أدناه كيفية استخدام هذه الفئة للعثور على أفضل تسع نتائج مطابقة للموقع الجغرافي "شارع Main" في كولورادو، وإضافتها إلى خريطة، ثم تضمينها في مستند 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)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.
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,
  );
}

المعلمات

الاسمالنوعالوصف
addressStringعنوان

الإرجاع

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,
  );
}

المعلمات

الاسمالنوعالوصف
latitudeNumberتمثّل هذه السمة خط العرض للنقطة.
longitudeNumberتمثّل هذه السمة خط الطول للنقطة.

الإرجاع

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,
);

المعلمات

الاسمالنوعالوصف
swLatitudeNumberخط العرض للزاوية الجنوبية الغربية للحدود
swLongitudeNumberخط طول الزاوية الجنوبية الغربية للحدود
neLatitudeNumberخط العرض للزاوية الشمالية الشرقية للحدود
neLongitudeNumberخط طول الزاوية الشمالية الشرقية للحدود

الإرجاع

Geocoder: عنصر Geocoder لتسهيل تسلسل عمليات الاستدعاء.

انظر أيضًا


setLanguage(language)

تضبط هذه السمة اللغة التي سيتم استخدامها في النتائج.

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

المعلمات

الاسمالنوعالوصف
languageStringمعرّف لغة BCP-47

الإرجاع

Geocoder: عنصر Geocoder لتسهيل تسلسل عمليات الاستدعاء.

انظر أيضًا


setRegion(region)

تضبط هذه السمة منطقة لاستخدامها عند تفسير أسماء المواقع الجغرافية. تتطابق رموز المناطق المتاحة مع أسماء نطاقات المستوى الأعلى التي يتم ترميزها حسب البلد والمتاحة على &quot;خرائط Google&quot;. على سبيل المثال، يتوافق رمز المنطقة "uk" مع "maps.google.co.uk".

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

المعلمات

الاسمالنوعالوصف
regionStringرمز المنطقة المطلوب استخدامه

الإرجاع

Geocoder: عنصر Geocoder لتسهيل تسلسل عمليات الاستدعاء.

انظر أيضًا