在 App maker 中使用 Places Library
Using Places Library in App maker
有没有办法从 App Maker 调用 PlacesServices 的 getDetails 函数?
我有来自 Geocoder 的地点 ID,但我希望能够获取有关该地点的详细信息。
目前 Apps 脚本中没有 built-in Places 服务,您需要完成以下步骤才能使其正常工作:
- 转到Google Cloud Console
创建一个全新的项目或使用与您的应用制作工具部署关联的项目:
使用左侧导航菜单转到 APIs & Services -> Dashboard
- 单击
+ Enable APIs and Services
按钮
- 搜索
Google Places API Web Service
并启用它
- 如果您没有
APIs & Services -> Credentials
并创建新的 API 密钥
- 回到应用制作工具! =) 创建服务器脚本:
var API_KEY = 'PUT_YOUR_API_KEY_HERE';
var PLACES_URL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=';
function getPlaceDetails_(placeId) {
var URL = PLACES_URL + placeId + '&key=' + API_KEY;
var response = UrlFetchApp.fetch(URL);
var json = response.getContentText();
var placeDetails = JSON.parse(json);
return placeDetails;
}
此代码段是进一步编写脚本的基石。您可以通过删除函数名称末尾的下划线来将其与 Calculated Model or just call it using google.script.run from client (note that for the second case you'll need to make this function public 一起使用。
有没有办法从 App Maker 调用 PlacesServices 的 getDetails 函数? 我有来自 Geocoder 的地点 ID,但我希望能够获取有关该地点的详细信息。
目前 Apps 脚本中没有 built-in Places 服务,您需要完成以下步骤才能使其正常工作:
- 转到Google Cloud Console
创建一个全新的项目或使用与您的应用制作工具部署关联的项目:
使用左侧导航菜单转到
APIs & Services -> Dashboard
- 单击
+ Enable APIs and Services
按钮 - 搜索
Google Places API Web Service
并启用它 - 如果您没有
APIs & Services -> Credentials
并创建新的 API 密钥 - 回到应用制作工具! =) 创建服务器脚本:
var API_KEY = 'PUT_YOUR_API_KEY_HERE';
var PLACES_URL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=';
function getPlaceDetails_(placeId) {
var URL = PLACES_URL + placeId + '&key=' + API_KEY;
var response = UrlFetchApp.fetch(URL);
var json = response.getContentText();
var placeDetails = JSON.parse(json);
return placeDetails;
}
此代码段是进一步编写脚本的基石。您可以通过删除函数名称末尾的下划线来将其与 Calculated Model or just call it using google.script.run from client (note that for the second case you'll need to make this function public 一起使用。