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