住所と地理座標を変換できます。
以下の例では、このクラスを使用して、コロラド州「Main St」の場所に対する上位 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'));
関連ドキュメント
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. 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
- 呼び出しの連鎖を容易にするジオコーダ オブジェクト。
関連ドキュメント
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)
場所名の解釈時に使用する地域を設定します。サポートされている地域コードは、Google マップでサポートされている ccTLD に対応しています。たとえば、地域コード「uk」は「maps.google.co.uk」に対応します。
// Creates a Geocoder with the region set to France. var geocoder = Maps.newGeocoder().setRegion('fr');
パラメータ
名前 | 型 | 説明 |
---|---|---|
region | String | リージョン コードを指定します。 |
リターン
Geocoder
- 呼び出しの連鎖を容易にするジオコーダ オブジェクト。