You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Buildfire地图插件如何读取集成设置中的API密钥?

在Buildfire插件中从「集成>API」选项卡读取谷歌地图API密钥

实现步骤:

  1. 先在Buildfire控制面板配置密钥字段

    • 进入你的插件管理页面,打开「集成>API」选项卡
    • 添加一个自定义API密钥字段,建议命名为googleMapsApiKey,保存配置
  2. 使用Buildfire SDK读取密钥
    利用buildfire.auth.getApiKeys()方法可以直接获取「集成>API」中配置的所有密钥,以下是完整代码示例:

// 读取配置的谷歌地图API密钥
buildfire.auth.getApiKeys((error, apiKeys) => {
  if (error) {
    console.error('读取API密钥出错:', error);
    return;
  }

  const googleMapsKey = apiKeys.googleMapsApiKey;
  if (!googleMapsKey) {
    console.warn('请先在「集成>API」选项卡配置谷歌地图API密钥');
    return;
  }

  // 动态加载谷歌地图并初始化
  loadGoogleMapsScript(googleMapsKey);
});

// 动态加载谷歌地图脚本
function loadGoogleMapsScript(apiKey) {
  const script = document.createElement('script');
  script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places`;
  script.async = true;
  script.defer = true;
  
  script.onload = () => {
    // 这里编写你的地图初始化逻辑
    const map = new google.maps.Map(document.getElementById('map-container'), {
      center: { lat: 40.7128, lng: -74.0060 },
      zoom: 12
    });
  };

  document.body.appendChild(script);
}
  1. 注意要点
    • 确保插件的权限配置中允许访问API密钥(一般默认开启,若出现权限问题可在插件设置中检查)
    • 该方法在插件的前端(widget)和后台(control)代码中都可以使用
    • 测试前务必在「集成>API」中填入有效的谷歌地图API密钥

内容的提问来源于stack exchange,提问作者Bruce Kuka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 16:23:19