在App Maker上搜索Google Map小部件的地址 [英] Address Search for the Google Map widget on App Maker

查看:52
本文介绍了在App Maker上搜索Google Map小部件的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到App Maker的Google Map小部件文档说我可以绑定地点"搜索框在App Maker中?

I see the Google Map widget documentation for App Maker says I can bind a datasource to it so that user can input an address to update the map. Is it possible to bind it to something like a Places search box in App Maker?

如果我不需要创建自己的数据源来启用地址搜索,那就太好了.

It'd be great if I don't need to create my own datasource to enable an address search.

推荐答案

您可以使用建议框计算出的数据源和<一个href ="https://developers.google.com/apps-script/reference/maps/geocoder" rel ="nofollow noreferrer"> Geocoder Apps脚本服务

/**
 * Creates address suggestion record.
 * @param {Object} geocode Geocode object received from Maps Geocoder.
 * @return {AddressSuggestion} Created suggestion record.
 */
function createAddressSuggestion_(geocode) {
  var record = app.models.AddressSuggestion.newRecord();
  record.Address = geocode.formatted_address;
  return record;
}


/**
 * Gets address suggestions Maps Geocoder.
 * @param {string} term Start of address string to search for.
 * @return {Array<AddressSuggestion>} Array of suggestion records.
 */
function getAddressSuggestions_(term) {
  // TODO: Uncomment to set clientId and Google Maps API Key
  // Maps.setAuthentication('your_client_id', 'your_signing_key');

  var response = Maps.newGeocoder().geocode(term);
  var geocodes = response.results;

  return geocodes.map(createAddressSuggestion_);
}

另一项重要重要的事情:您需要说出建议框"来将您的数据源作为整个记录来处理,否则它将过滤出与您的_startsWith词不完全匹配的所有结果:

One more important important thing: you need to say Suggest Box to handle your datasource as whole records otherwise it will filter out all results that have no exact match with your _startsWith term:

这篇关于在App Maker上搜索Google Map小部件的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆