Class Geocoder  |  Apps Script  |  Google for Developers (original) (raw)

Geocoder

מאפשרת המרה בין כתובת לבין קואורדינטות גיאוגרפיות.
בדוגמה הבאה מוסבר איך אפשר להשתמש בכיתה הזו כדי למצוא את תשעת התאמות החיפוש המובילות למיקום '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 הפונקציה מקבלת את הנקודות הגיאוגרפיות המשוערות של כתובת נתונה.
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, ); }

פרמטרים

שם סוג תיאור
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. לדוגמה, קוד האזור 'uk' תואם לכתובת 'maps.google.co.uk'.

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

פרמטרים

שם סוג תיאור
region String קוד האזור שבו רוצים להשתמש

חזרה

[Geocoder](#) – אובייקט Geocoder כדי להקל על שרשור של קריאות

ראה גם

אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers‏.‏ Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.

עדכון אחרון: 2024-12-22 (שעון UTC).