Google API 用于从现有 Google 地图中检索标记

Google API for retrieving markers from an existing Google Map

浏览 Google 云目录中的所有 API:s,我无法弄清楚它们是否能够从使用 [= 创建的现有地图中返回标记列表25=]地图。

我的一个客户创建了 the following map,由于仅将其嵌入到他们的网站上看起来很糟糕,因此我想使用地图 JavaScript API 来创建自定义地图,带有所有这些标记。

我是否需要重新设置所有这些标记,以便我可以实际循环并将它们全部添加到地图中,或者是否有 任何 方式供我调用REST API 使用现有地图中的 ID 来避免这种双重工作?

那是一张“我的地图”。您可以使用 mid=123NHZo7-vcfBAhYpF_YWbrgEpMQKmlLayer 上将它们作为 KML 加载,如下所示:fiddle

  var ctaLayer = new google.maps.KmlLayer({
    url: 'https://www.google.com/maps/d/kml?mid=123NHZo7-vcfBAhYpF_YWbrgEpMQ',
    map: map
  });

相关问题:

  • Render a My Maps using Google Maps JavaScript API

代码片段:

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 11,
    center: {
      lat: 41.876,
      lng: -87.624
    }
  });

  var ctaLayer = new google.maps.KmlLayer({
    url: 'https://www.google.com/maps/d/kml?mid=123NHZo7-vcfBAhYpF_YWbrgEpMQ',
    map: map
  });
}
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#map {
  height: 100%;
}
<div id="map"></div>
<!-- add your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?callback=initMap&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk">
</script>