谷歌地图Api绘制一个圆圈

时间:2014-01-14 19:16:28

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

嗨我有一个谷歌地图api的问题,我使用图书馆绘图,不知道这是否正常,但当我正在使用圆形绘图时,开始画这个不会出现在地图仅在圆圈完成时出现,但另一个控制器如多边形或矩形它出现在开始绘制的瞬间,我确实复制了谷歌地图api在他们的页面中的示例并且发生了同样的事情..

一些解决方案..感谢您的帮助。

这是Google maps API的代码

<!DOCTYPE html>
<html>
  <head>
    <title>Drawing tools</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=drawing"></script>
    <script>
function initialize() {
  var mapOptions = {
    center: new google.maps.LatLng(-34.397, 150.644),
    zoom: 8
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);

  var drawingManager = new google.maps.drawing.DrawingManager({
    drawingMode: google.maps.drawing.OverlayType.MARKER,
    drawingControl: true,
    drawingControlOptions: {
      position: google.maps.ControlPosition.TOP_CENTER,
      drawingModes: [
        google.maps.drawing.OverlayType.MARKER,
        google.maps.drawing.OverlayType.CIRCLE,
        google.maps.drawing.OverlayType.POLYGON,
        google.maps.drawing.OverlayType.POLYLINE,
        google.maps.drawing.OverlayType.RECTANGLE
      ]
    },
    markerOptions: {
      icon: 'images/beachflag.png'
    },
    circleOptions: {
      fillColor: '#ffff00',
      fillOpacity: 1,
      strokeWeight: 5,
      clickable: false,
      editable: true,
      zIndex: 1
    }
  });
  drawingManager.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

加载地图后尝试使用此代码。它为我工作。

var rad=9;
var draw_circle=null;
draw_circle = new google.maps.Circle({
                                     center: new google.maps.LatLng(32.0833, 34.8000),
                                     radius: rad,
                                     strokeColor: "#FFFFFF",
                                     strokeOpacity: 0.8,
                                     strokeWeight: 2,
                                     fillColor: "#FFFFFF",
                                     fillOpacity: 0.35,
                                     map: map
                                     });

希望它有所帮助。!