问题描述
我看到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.
推荐答案
您可以使用建议框,计算出的数据源和 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小部件的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!