【问题标题】:Is it possible to put a big circle on a map using Google Map JavaScript API/JavaScript? [closed]是否可以使用 Google Map JavaScript API/JavaScript 在地图上放置一个大圆圈? [关闭]
【发布时间】:2021-04-10 18:09:49
【问题描述】:

这是我目前拥有的:

我正在寻找这样的东西(对丑陋的圆圈感到抱歉,想象它是一个完美的圆圈):

这是我目前的 JavaScript:

let map;

function initMap() {
  map = new google.maps.Map(document.getElementById("map"), {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8,
  });
}

把它放在中心也很好,因为我可以微调坐标。

【问题讨论】:

  • 是的,Maps API 支持 Circles。可以在here找到文档。
  • 有没有想过看看文档?那里的一切都很详细,还有例子。除此之外,这里有几十个(如果不是几百个)关于在地图上画一个圆圈的相关问题;其中大部分包含代码示例。
  • @MrUpsidown 抱歉找不到

标签: javascript api google-maps


【解决方案1】:

虽然new google.maps.Circle可以创建圈子

<!DOCTYPE html>
<html>
  <head>
    <title>Circles</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <!-- jsFiddle will insert css and js -->
  </head>
  <body>
    <div id="map"></div>

    <!-- Async script executes immediately and must be after any DOM elements used in callback. -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBIwzALxUPNbatRBj3Xi1Uhp0fFzwWNBkE&callback=initMap&libraries=&v=weekly"
      async
    ></script>
  </body>
<script>
function initMap() {
  // Create the map.
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 4,
    center: { lat: 37.09, lng: -95.712 },
    mapTypeId: "terrain",
  });

    const cityCircle = new google.maps.Circle({
      strokeColor: "#FF0000",
      strokeOpacity: 0.8,
      strokeWeight: 2,
      fillColor: "#FF0000",
      fillOpacity: 0.0,
      map,
      center: { lat: 41.878, lng: -87.629 },
      radius: Math.sqrt( 2714856) * 100,
    });
}
</script>
</html>

https://jsfiddle.net/api/post/library/pure/

【讨论】:

  • 非常感谢!不过你的小提琴不起作用
猜你喜欢
  • 1970-01-01
  • 2011-04-15
  • 2015-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多