【问题标题】:Google Maps embed search not showing results?谷歌地图嵌入搜索不显示结果?
【发布时间】:2021-12-28 20:14:31
【问题描述】:

我正在尝试使用 Google Maps embed API 在纬度/经度坐标周围的区域内搜索地点。下面的代码正确显示了地图,但它显示的搜索结果是针对不同位置的。在一个浏览器上,它认为我在意大利罗马,另一个在我的实际位置附近。

有没有办法获取地图中显示区域的搜索结果?

<iframe 
  width="600" 
  height="450" 
  style="border:0" 
  allowfullscreen 
  src="https://www.google.com/maps/embed/v1/search?key=APIKEY&q=Restaurant&center=43.98444444,-88.55694444&zoom=14"> </iframe>

【问题讨论】:

    标签: search google-maps-api-3 maps embed


    【解决方案1】:

    来自文档:

    search mode
    搜索模式显示整个可见地图区域的搜索结果。建议定义搜索的位置,方法是在搜索词中包含一个位置(record+stores+in+Seattle),或者包含一个中心和缩放参数来限制搜索。

    如果我将地图的中心点转换为地址(2982 Eide Rd, Oshkosh, WI 54902)并将其添加到查询中,我会在地图上显示结果。

    proof of concept fiddle

    代码 sn-p

    <iframe 
      width="600" 
      height="450" 
      style="border:0" 
      allowfullscreen 
      src="https://www.google.com/maps/embed/v1/search?q=Restaurants near 2982 Eide Rd, Oshkosh, WI 54902&center=43.98444444,-88.55694444&zoom=12&key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg"> </iframe>

    【讨论】:

      【解决方案2】:

      谷歌地图允许你指定一个区域来避免这种问题。像这样设置地图的区域(以英国为例):

      <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&region=UK&callback=initMap" async defer></script>
      

      在初始化 google 地图脚本时,在 API 密钥之后添加 region=YOUR_REGION_CODE

      以您为例,您可以尝试以下操作:

      https://www.google.com/maps/embed/v1/search?key=APIKEY&region=IT&q=Restaurant&center=43.98444444,-88.55694444&zoom=14"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-10
        • 2019-03-27
        • 1970-01-01
        • 2011-08-06
        • 2014-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多