מאפשרת המרה בין כתובת לקואורדינטות גיאוגרפיות.
בדוגמה הבאה אפשר לראות איך משתמשים במחלקה הזו כדי למצוא את תשעת המיקומים הכי מתאימים למיקום 'Main St' בקולורדו, להוסיף אותם למפה ואז להטמיע אותה במסמך חדש ב-Google Docs.
// 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'));
ראה גם
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
geocode(address) | Object | מקבל את הנקודות הגיאוגרפיות המשוערות של כתובת נתונה. |
reverse | Object | קבלת הכתובות המשוערות של נקודה גיאוגרפית נתונה. |
set | Geocoder | הגדרת הגבולות של אזור שצריך לקבל עדיפות נוספת בתוצאות. |
set | Geocoder | הגדרת השפה שבה יוצגו התוצאות. |
set | 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, ); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
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 שמכיל את נתוני המרת קואורדינטות לכתובות (reverse geocoding), כפי שמתואר כאן.
ראה גם
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, );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
sw | Number | קו הרוחב של הפינה הדרום-מערבית של הגבולות. |
sw | Number | קו האורך של הפינה הדרום-מערבית של הגבולות. |
ne | Number | קו הרוחב של הפינה הצפון-מזרחית של הגבולות. |
ne | Number | קו האורך של הפינה הצפון-מזרחית של הגבולות. |
חזרה
Geocoder – אובייקט הגיאו-קודר כדי לאפשר שרשור של קריאות.
ראה גם
setLanguage(language)
הגדרת השפה שבה יוצגו התוצאות.
// Creates a Geocoder with the language set to French. const geocoder = Maps.newGeocoder().setLanguage('fr');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
language | String | מזהה שפה בפורמט BCP-47. |
חזרה
Geocoder – אובייקט הגיאו-קודר כדי לאפשר שרשור של קריאות.
ראה גם
setRegion(region)
מגדירה אזור לשימוש כשמפרשים שמות של מיקומים. קודי האזורים הנתמכים תואמים לדומיינים הנתמכים ברמה העליונה (ccTLD) במפות Google. לדוגמה, קוד האזור uk מתאים לכתובת maps.google.co.uk.
// Creates a Geocoder with the region set to France. const geocoder = Maps.newGeocoder().setRegion('fr');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
region | String | קוד האזור שבו רוצים להשתמש. |
חזרה
Geocoder – אובייקט הגיאו-קודר כדי לאפשר שרשור של קריאות.