AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[google-maps](coding)

Martin Hope
user460114
Asked: 2025-04-07 23:45:09 +0800 CST

循环并在 html 地图上添加多个 Google 地图标记

  • 5

现有代码如下,并未循环遍历 gmp-map html 元素来添加标记,而只是向其中一个元素添加标记。需要在 html 代码本身或 JavaScript 代码中使用循环。

<body>
    <cfoutput>
        <gmp-map
            center="#vLat#,#vLng#"
            zoom="10"
            map-id="DEMO_MAP_ID"
            style="height: 400px"
        >
        <cfloop query="qNearbyTradies">
            <gmp-advanced-marker
                position="#lat#,#lng#"
                title="#company_name# - #sublocality#, #locality#"
                gmpClickable=true
            ></gmp-advanced-marker>
        </cfloop>
    </cfoutput>
</body>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap&key=[KEY]&libraries=maps,marker&v=beta" async defer></script>
      
    
<script>
    async function initMap() {
        // I assume a javascript loop would begin here somewhere
        const m = document.querySelector("gmp-advanced-marker");
        m.addListener("click", ({ domEvent, latLng }) => {
            const { target } = domEvent;
            const infoWindow = new google.maps.InfoWindow;
            infoWindow.close();
            infoWindow.setContent(m.title);
            infoWindow.open(m.map, m);
        });
    }
    
    window.initMap = initMap;
</script>

我之前用 JavaScript 写了一些代码来生成公司数组,但在决定用 HTML 生成地图后,HTML 代码中已经有一个循环,如果可能的话,最好在这个循环中生成所有可点击事件。我正在寻找实现这个目标的指南。

google-maps
  • 1 个回答
  • 35 Views
Martin Hope
onesiumus
Asked: 2025-02-08 07:49:55 +0800 CST

使用 Google Places Insights API 搜索酒吧时如何排除与食物相关的次要类型?

  • 6

我正在尝试使用新的 Places Insights API 来统计我所在城市的酒吧数量,但得到了意想不到的结果。我想统计主要以酒吧为主但不是以酒吧为特色的餐馆。我当前的查询如下所示:

{
    "insights": ["INSIGHT_COUNT"],
    "filter": {
        "locationFilter": {
            "region": {
                "place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
            }
        },
        "typeFilter": {
            "includedTypes": ["bar"]
        }
    }
}

这返回了太多结果,因为它包括了以“酒吧”作为次要类型的餐馆。我该如何修改查询以仅获取以酒吧为主的地点?

google-maps
  • 1 个回答
  • 15 Views
Martin Hope
Volodymyr
Asked: 2024-11-15 23:07:30 +0800 CST

Maps JavaScript API 的动态库导入在 Apps 脚本中不起作用

  • 5

我正在尝试切换到动态库导入 API(来自过时的脚本标签)。我根据Google 电子表格中有关 Apps Script的文档制作了一个示例。结果,我希望在浏览器中获得 Google 地图,但在控制台中收到错误

userCodeAppPanel:2 未捕获的 SyntaxError:输入意外结束 userCodeAppPanel:6 未捕获(在承诺中)TypeError:无法读取未定义的属性(读取‘importLibrary’)在 initMap(userCodeAppPanel:6:39)在 userCodeAppPanel:15:1

以下是 Apps 脚本的代码:

<!doctype html>
<html>
  <head>
    <title>Simple Map</title>
    <script>
let map; 
// initMap is now async
async function initMap() { 
    // Request libraries when needed, not in the script tag.
    const { Map } = await google.maps.importLibrary("maps");
    // Short namespaces can be used.
    map = new Map(document.getElementById("map"), {
        center: { lat: 40.72476, lng: -74.04843 },
        zoom: 8,
    });

}

initMap();
</script>
  </head>
  <body>
    <div id="map"></div>
  
   <script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src="https://maps.${c}apis.com/maps/api/js?"+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})
        ({key: "AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg", v: "weekly"});</script>

<style>
#map {
  height: 100%;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: grey;
}
</style>
  </body>
</html>

但在jsfiddle中同样的代码处理没有错误(结果显示为地图)。

我认为 Apps Script 中缺少某些内容。请帮助我了解原因并在动态库导入上运行代码

更新:修复引号部分解决了问题(感谢 Tanaike)。现在错误仍然存​​在:

未捕获(在承诺中)TypeError:无法读取未定义的属性(读取“importLibrary”)

要重现错误,您可以使用带有模态窗口调用的Google 电子表格。首先,按 F12 在浏览器中显示控制台,然后按脚本按钮并打开地图

google-maps
  • 1 个回答
  • 72 Views
Martin Hope
Angela M
Asked: 2024-08-06 00:19:16 +0800 CST

脚本错误,无法获取两个地址之间的时间和距离

  • 4

我正在尝试设置一个谷歌表格,我可以在其中输入两个地址,并从谷歌地图的 Excel 表格中获取行驶距离和时间

我有下面的脚本 - 但它一直出现错误 - 错误是异常:无效参数:来源 GOOGLEMAPS @GOOGLEMAPS.gs:4

我的脚本如下 your text

`function GOOGLEMAPS(start_address,end_address,return_type) {

  var mapObj = Maps.newDirectionFinder();
  mapObj.setOrigin(start_address);
  mapObj.setDestination(end_address);
  var directions = mapObj.getDirections();

  var getTheLeg = directions["routes"][0]["legs"][0];

  var meters = getTheLeg["distance"]["value"];

  switch(return_type){
    case "miles":
      return meters * 0.000621371;
      break;
      case "minutes":
      //get duration in seconds
      var duration = getTheLeg["duration"]["value"];
      //convert to minutes and return
      return duration / 60;
      break;
    case "kilometers":
      return meters / 1000;
      break;
    default:
      return "error:wrong unit type";
  }
}`
google-maps
  • 1 个回答
  • 14 Views
Martin Hope
Hoy Cheung
Asked: 2024-01-21 01:54:30 +0800 CST

如何将 HEIC 地理位置转换为 google lng lat 格式

  • 6

我保存了用我的 iPhone 拍摄的 HEIC 照片。我打开它并尝试找出纬度和经度数字。它显示的内容与google显示的格式完全不同,并且无法搜索到。如何转换这些数字以符合 Google 地图?

数字如下: 纬度:39;53;0.6499999 经度:116;9;24.4199999 HEIC 格式 谷歌格式

google-maps
  • 1 个回答
  • 12 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve